public async Task <ActionResult> Create([Bind("BoxDescription,DateBoxCreated,BoxCreatedBy,BoxCreatorID")] Box box)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    baseAsyncBoxRepo.Insert(box);
                    await baseAsyncBoxRepo.SaveAsync();

                    return(RedirectToAction("Index"));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            PopulateBoxCreatorDropDownList(box.BoxCreatorID);
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("FolderName,FolderDescription,BoxID,CustDataCIFNo")] Folder folder)
        {
            var fex = await baseAsyncFolderRepo.GetAllAsync(m => m.BoxID == folder.BoxID);

            var awe = new HashSet <string>(fex.Select(c => c.CustDataCIFNo));

            if (awe.Contains(folder.CustDataCIFNo))
            {
                return(RedirectToAction("Error", "Home"));
            }

            try
            {
                baseAsyncFolderRepo.Insert(folder);
                await baseAsyncFolderRepo.SaveAsync();

                return(RedirectToAction("Index", new RouteValueDictionary(new { controller = "Box", action = "Index", id = folder.BoxID })));
            }
            catch
            {
                return(View());
            }
        }