public ActionResult Save(AssetLocation assetLocation) { List <AssetLocation> assetLocations = assetmanager.GetAll(); ViewBag.AssetLocationList = assetLocations; List <Organization> organizations = manager.GetAll(); ViewBag.organizationList = organizations.ToList(); List <OrganizationBranch> organizationBranches = orgManager.OrganizationBranches(); ViewBag.OrgBranchList = organizationBranches; if (assetLocation.Name == null || assetLocation.ShortName == null || assetLocation.OrganigationId == 0 || assetLocation.OrganigationId == 0) { ViewBag.message = "Input filed is requierd"; } else { if (assetLocation.ShortName.Length > 5) { ViewBag.message = "Short name filed is to be maximum 5 digit"; } else { bool IsShortNameExist = assetmanager.IsShortNameExist(assetLocation.ShortName); if (IsShortNameExist) { ViewBag.message = "Short name is already exist !"; } else { bool Save = assetmanager.Add(assetLocation); if (Save) { ViewBag.message = "Save Location Successfull !"; } else { ViewBag.message = "Save failed"; } } } } return(View()); }
public ActionResult Save(AssetLocationViewModel assetLocationVm) { var assetLocationVmDropdown = new AssetLocationViewModel() { Organizations = _organizationManager.GetAll(), Branches = new List <Branch>() { } }; ModelState.Remove("Id"); if (ModelState.IsValid) { if (assetLocationVm.Id == 0) { bool isShortNameExist = _assetLocationManager.IsShortNameExist(assetLocationVm.ShortName, assetLocationVm.OrganizationId, assetLocationVm.BranchId); if (isShortNameExist) { ViewBag.Message = "This Location Short Name already Exist"; return(View("LocationForm", assetLocationVmDropdown)); } var location = new AssetLocation() { OrganizationId = assetLocationVm.OrganizationId, BranchId = assetLocationVm.BranchId, Name = assetLocationVm.Name, ShortName = assetLocationVm.ShortName, BranchCode = assetLocationVm.LocationCode }; _assetLocationManager.Add(location); ModelState.Clear(); return(View("LocationForm", assetLocationVmDropdown)); } var locationInDb = _assetLocationManager.Get(assetLocationVm.Id); locationInDb.Id = assetLocationVm.Id; locationInDb.Name = assetLocationVm.Name; locationInDb.ShortName = assetLocationVm.ShortName; locationInDb.BranchCode = assetLocationVm.LocationCode; locationInDb.OrganizationId = assetLocationVm.OrganizationId; locationInDb.BranchId = assetLocationVm.BranchId; _assetLocationManager.Update(locationInDb); ModelState.Clear(); return(View("LocationList")); } return(View("LocationForm", assetLocationVmDropdown)); }
public ActionResult Create([Bind(Include = "Id,OrganizationId,BranchId,Name,ShortName,AssetLocationCode")] AssetLocation assetLocation) { if (ModelState.IsValid) { bool isName = _assetLocationManager.IsAssetLocationNameExist(assetLocation.Name); bool isShortName = _assetLocationManager.IsAssetLocatoinShortNameExist(assetLocation.ShortName); bool isCode = _assetLocationManager.IsAssetLocationByCodeExist(assetLocation.AssetLocationCode); if (isName) { ViewBag.NameCssClass = "Alert Alert-warning"; ViewBag.NameMessageType = "Warning"; ViewBag.NameMessage = "This Asset Location already exist"; } else if (isShortName) { ViewBag.ShortNameCssClass = "Alert Alert-warning"; ViewBag.ShortNameMessageType = "Warning"; ViewBag.ShortNameMessage = "This asset location short name already exist!"; } else if (isCode) { ViewBag.CodeCssClass = "Alert Alert-warning"; ViewBag.MessageType = "Warning"; ViewBag.Message = "This asset location code already exist!"; } else { _assetLocationManager.Add(assetLocation); return(RedirectToAction("Index")); } } ViewBag.BranchId = new SelectList(_branchManager.GetAll(), "Id", "Name", assetLocation.BranchId); ViewBag.OrganizationId = new SelectList(_organizationManager.GetAll(), "Id", "Name", assetLocation.OrganizationId); return(View(assetLocation)); }