Ejemplo n.º 1
0
        public ActionResult Add(AddArea narea)
        {
            List <SalePoint> salepointlist = AgroExpressDBAccess.GetallEnabledSalePoint();

            if (salepointlist != null)
            {
                narea.salepointlist = salepointlist.Select(x => new SelectListItem
                {
                    Value = x.PKSalePointID.ToString(),
                    Text  = x.SalePointName
                });
            }

            if (ModelState.IsValid)
            {
                if (AgroExpressDBAccess.isAreaExist(narea.AreaName))
                {
                    ModelState.AddModelError("AreaName", "Area name already exist!!!");
                    return(View(narea));
                }
                else
                {
                    Area newentry = new Area();

                    newentry.AreaName    = narea.AreaName;
                    newentry.SalePointId = narea.SalePointId;
                    newentry.IsDeleted   = false;
                    if (AgroExpressDBAccess.AddArea(newentry))
                    {
                        ViewBag.success = "Area added successfully";
                        ModelState.Clear();
                        AddArea tem = new AddArea();
                        if (salepointlist != null)
                        {
                            tem.salepointlist = salepointlist.Select(x => new SelectListItem
                            {
                                Value = x.PKSalePointID.ToString(),
                                Text  = x.SalePointName
                            });
                        }

                        return(View(tem));
                    }
                }
            }
            return(View(narea));
        }