Click here to Skip to main content
15,916,030 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i need help with logic where a form contains parameters such App Icon,App Title,App desription,Offer Starting Date and Offer Ending date..

The Condition when i click submit button is suppose There 2 apps present on Same Date it should ask user to Select another date.. but my logic doesnt work properly.. i am able to submit even 3 apps in Same Date

C#
public ActionResult SubmitApp(FormCollection fc)
{

    try
    {
        if (Session["userid"] != null)
        {

            if (string.IsNullOrEmpty(fc["actualprice"]) || string.IsNullOrEmpty(fc["offerprice"]) || string.IsNullOrEmpty(fc["datepickerstart"]) || string.IsNullOrEmpty(fc["datepickerend"]) || string.IsNullOrEmpty(fc["link"]) || string.IsNullOrEmpty(fc["title"]))
            {
                ViewBag.Success = "Please fill all the fields"; return View();
            }
            else
            {

                if (ModelState.IsValid)
                {

                    Submit_App sa = new Submit_App();
                    sa.App_type = fc["Fapp"];
                    sa.Actual_Price = Decimal.Parse(fc["actualprice"]);
                    sa.offerprice = Decimal.Parse(fc["offerprice"]);
                    sa.App_Description = fc["description"];
                    sa.App_Title = fc["title"];
                    if (fc["link"].StartsWith("https://")) { sa.iTunes_Link = fc["link"]; }
                    else
                    {
                        sa.iTunes_Link = "https://" + fc["link"];
                    }
                    sa.UserID = (long)Session["userid"];
                    sa.StartDate = DateTime.ParseExact(@fc["datepickerstart"], "dd-MM-yyyy HH:mm", CultureInfo.InvariantCulture);
                    sa.EndDate = DateTime.ParseExact(@fc["datepickerend"], "dd-MM-yyyy HH:mm", CultureInfo.InvariantCulture);
                    sa.downloads_count = 0;

                    if (sa.StartDate > sa.EndDate)
                    {
                        ViewBag.success = "End Date should be higher than Start Date";
                        return View();
                    }
                    var id = Session["userid"];

                    var stdate = DateTime.ParseExact((@fc["datepickerstart"]), "dd-MM-yyyy HH:mm", CultureInfo.InvariantCulture);
                    var enddate = DateTime.ParseExact((@fc["datepickerend"]), "dd-MM-yyyy HH:mm", CultureInfo.InvariantCulture);
                    var contents = from u in entity.Submit_App
                                   where ((u.StartDate == stdate && u.EndDate == enddate) || (u.StartDate <= stdate && u.EndDate >= enddate) || (u.StartDate >= stdate && u.EndDate <= enddate)) //&& u.UserID == (long)id
                                   select new { u.EndDate, u.StartDate };

                    int count = 0; //s = contents.Count();
                    foreach (var item in contents)
                    {
                        //if ((item.StartDate == stdate && item.EndDate == enddate) || (item.StartDate <= stdate && item.EndDate >= enddate) || (item.StartDate >= stdate && item.EndDate <= enddate))
                        //{
                        count++; //}
                    }
                    if (count < 2)
                    {
                        string icons=save(Request.Files["icon"], "~/icons");
                        string images=save(Request.Files["img"], "~/images");
                        if ((images==null || images=="") || (icons==null || icons==""))
                        {
                            ViewBag.success = "Please Upload App Icon/Image";
                            return View();
                        }
                        else
                        {
                            sa.App_Icon = "/icons/" + icons;
                            sa.App_Image = "/images/" + images;

                            entity.AddToSubmit_App(sa);
                            entity.SaveChanges();
                            Login_Table app = entity.Login_Table.ToList().Where(x => x.UserID == (long)Session["userid"]).First();
                            app.Apps_Published = app.Apps_Published + 1;
                            entity.SaveChanges();
                            ViewBag.success = "App published succesfully";
                            return View();
                        }
                    }
                    else
                    {
                        ViewBag.success = "2 Apps registered on your selected date choose another date";
                        return View();
                    }

                }
            }
        }
        else { return RedirectToAction("Login", "Login"); }
        return View();
    }
    catch(Exception ex)
    {
        ViewBag.success = ex.Message.ToString();
        return View();
    }
    //}

}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900