コード例 #1
0
        private IJPDetailModel MapToViewModel(IJPDetail asset)
        {
            var status = DbContext.Status.Where(x => x.Id == asset.StatusId).FirstOrDefault();

            IJPDetailModel iJPDetailModel = new IJPDetailModel()
            {
                Id                  = asset.Id,
                Job                 = asset.Job,
                Experience          = asset.Experience,
                LastDate            = asset.LastDate,
                ApplicationReceived = asset.ApplicationReceived,
                Quantity            = asset.Quantity,

                Status   = status != null ? status.Status1 : String.Empty,
                StatusId = status.Id,

                StatusSelectList = new SelectList(DbContext.Status
                                                  //.Where(fs => fs.IsActive && !fs.IsDeleted)
                                                  .Select(x => new { x.Id, x.Status1 }),
                                                  "Id",
                                                  "Status1", asset.Id)
            };

            return(iJPDetailModel);
        }
コード例 #2
0
        public async Task <ActionResult> Edit(IJPDetailModel assetVM)
        {
            assetVM.StatusSelectList = GetFacilitiySitesSelectList(assetVM.StatusId);

            if (!ModelState.IsValid)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(View(Request.IsAjaxRequest() ? "_EditPartial" : "Edit", assetVM));
            }

            IJPDetail asset = MaptoModel(assetVM);

            DbContext.IJPDetails.Attach(asset);
            DbContext.Entry(asset).State = EntityState.Modified;
            var   task = DbContext.SaveChangesAsync();
            await task;

            if (task.Exception != null)
            {
                ModelState.AddModelError("", "Unable to update the Asset");
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(View(Request.IsAjaxRequest() ? "_EditPartial" : "Edit", assetVM));
            }

            if (Request.IsAjaxRequest())
            {
                return(Content("success"));
            }

            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public async Task <ActionResult> DeleteAsset(int Id)
        {
            var asset = new IJPDetail {
                Id = Id
            };

            DbContext.IJPDetails.Attach(asset);
            DbContext.IJPDetails.Remove(asset);

            var   task = DbContext.SaveChangesAsync();
            await task;

            if (task.Exception != null)
            {
                ModelState.AddModelError("", "Unable to Delete the Asset");
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                IJPDetailModel assetVM = MapToViewModel(asset);
                return(View(Request.IsAjaxRequest() ? "_DeletePartial" : "Delete", assetVM));
            }

            if (Request.IsAjaxRequest())
            {
                return(Content("success"));
            }

            return(RedirectToAction("Index"));
        }
コード例 #4
0
        public async Task <ActionResult> Create(IJPDetailModel IJPDetail)
        {
            IJPDetail.StatusSelectList = GetStatusSelectList();

            //if (!ModelState.IsValid)
            //    return View("_CreatePartial", IJPDetail);

            IJPDetail asset = MaptoModel(IJPDetail);

            DbContext.IJPDetails.Add(asset);
            var   task = DbContext.SaveChangesAsync();
            await task;

            if (task.Exception != null)
            {
                ModelState.AddModelError("", "Unable to add the Asset");
                //return View("_CreatePartial", IJPDetail);
                return(RedirectToAction("Index"));
            }

            if (Request.IsAjaxRequest())
            {
                return(Content("success"));
            }

            return(RedirectToAction("Index"));
        }
コード例 #5
0
        private IJPDetail MaptoModel(IJPDetailModel assetVM)
        {
            var       status = DbContext.Status.Where(x => x.Id == assetVM.StatusId).FirstOrDefault();
            IJPDetail asset  = new IJPDetail()
            {
                Id                  = assetVM.Id,
                Job                 = assetVM.Job,
                Experience          = assetVM.Experience,
                LastDate            = assetVM.LastDate,
                ApplicationReceived = assetVM.ApplicationReceived,
                Quantity            = assetVM.Quantity,
                StatusId            = assetVM.StatusId
            };

            return(asset);
        }