Exemple #1
0
        public ActionResult Create(LocationViewModel location)
        {
            if (ModelState.IsValid)
            {
                var dept = new Location
                {
                    Id           = location.Id,
                    LocationName = location.LocationName,
                    Date         = location.Date,
                    Description  = location.Description
                };
                _locationmanager.Add(dept);
                _locationmanager.GetAll().ToList();
                _locationmanager.SaveChanges();
                TempData["Success"] = "Added Successfully!";

                //return Json(new { success = true, messsage = "Saved Successfully" }, JsonRequestBehavior.AllowGet);
                //TempData["message"] = string.Format("{0} has been saved.", location);
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(location));
            }


            //return View();
        }
Exemple #2
0
        public ActionResult Create(Location location)
        {
            if (ModelState.IsValid && location != null)
            {
                ModelState.Clear();
                try
                {
                    var locationList = _locationManager.GetAll(c => true);

                    int locationExist = locationList
                                        .Where(c => c.OrganizationId == location.OrganizationId)
                                        .Where(c => c.BranchId == location.BranchId)
                                        .Where(c => c.ShortName == location.ShortName)
                                        .Count();

                    if (locationExist > 0)
                    {
                        location.ShortName = null;
                        ModelState.AddModelError("ShortName",
                                                 "Short name for the location already exists");
                    }
                    else
                    {
                        if (_locationManager.Add(location))
                        {
                            ViewBag.Msg = "location added successfully!";
                            return(View());
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                }
            }

            return(View(location));
        }