public AssetApplication JoinApplicatedAssets(AssetApplication application) { IEnumerable<ApplicatedAsset> orig_applicated_assets = application.ApplicatedAssets.ToList(); IList<ApplicatedAsset> joined_applicated_assets = new List<ApplicatedAsset>(); foreach (ApplicatedAsset orig_asset in orig_applicated_assets) { ApplicatedAsset joined_asset = joined_applicated_assets.FirstOrDefault(t => t.AssetId == orig_asset.AssetId); if (joined_asset == null) { if (orig_asset.Id == 0) orig_asset.Id = db.GenerateIdFor(IdentityForTPC.ASSET_BASE); joined_applicated_assets.Add(orig_asset); } else { joined_asset.Count += orig_asset.Count; } } application.ApplicatedAssets = joined_applicated_assets; return application; }
public ActionResult Create(int TimeId, DateTime Date, int ClubId, int[] item_id, int[] item_borrow_count) { AssetApplication asset_application = new AssetApplication { Club = unitOfWork.Clubs.Find(ClubId), ApplicantUserName = User.Identity.Name, Date = Date, Status = "n", //Time = unitOfWork.Times.Find(TimeId), ApplicatedAssets = new List<ApplicatedAsset>() }; asset_application.Times = new List<Time>(); asset_application.Times.Add(unitOfWork.Times.Find(TimeId)); int i = 0; foreach(int s in item_id) { asset_application.ApplicatedAssets.Add( new ApplicatedAsset { Asset = new Asset { Name = unitOfWork.Assets.Find(s).Name, Count = item_borrow_count[i] } }); i++; } unitOfWork.Applications.Add(asset_application); unitOfWork.SaveChanges(); //ViewBag.ClubId = new SelectList(unitOfWork.Clubs.ToList(), "Id", "Id"); //ViewBag.ApplicantUserName = User.Identity.Name; //ViewBag.Id = //ViewBag.TimeId = new SelectList(unitOfWork.Times.ToList(), "Id", "TimeName"); //ViewBag.SubEventId = new SelectList(unitOfWork.SubEvents.ToList(), "Id", "Title"); return View(); }
public ActionResult Edit(AssetApplication assetapplication) { if (ModelState.IsValid) { unitOfWork.AssetApplications.Update(assetapplication); unitOfWork.SaveChanges(); return RedirectToAction("Index"); } ViewBag.ClubId = new SelectList(unitOfWork.Clubs.ToList(), "Id", "Id", assetapplication.ClubId); ViewBag.ApplicantUserName = new SelectList(unitOfWork.Users.ToList(), "UserName", "Name", assetapplication.ApplicantUserName); ViewBag.Id = new SelectList(unitOfWork.ApplicationRejectReasons.ToList(), "ApplicationId", "Reason", assetapplication.Id); //ViewBag.TimeId = new SelectList(unitOfWork.Times.ToList(), "Id", "TimeName", assetapplication.TimeId); ViewBag.SubEventId = new SelectList(unitOfWork.SubEvents.ToList(), "Id", "Title", assetapplication.SubEventId); return View(assetapplication); }
public void VerifyAssetApplication(AssetApplication application, bool is_passed, bool save = true) { if (is_passed) { application.Status = Application.PASSED; AssetAssignment assignment = new AssetAssignment { ApplicantUserName = application.ApplicantUserName, ClubId = application.ClubId ?? 0, Date = application.ApplicatedDate, Times = application.Times, AssignedAssets = new List<AssignedAsset>() }; foreach (ApplicatedAsset asset in application.ApplicatedAssets) { assignment.AssignedAssets.Add(new AssignedAsset { Id = db.GenerateIdFor(IdentityForTPC.ASSET_BASE), AssetId = asset.AssetId, Count = asset.Count }); } application.Assignment = assignment; } else { application.Status = Application.FAILED; } if (save) db.SaveChanges(); }
public void UpdateAssetApplication(AssetApplication orig_application, AssetApplication new_application) { orig_application.ApplicatedDate = orig_application.SubEvent.Date; orig_application.Date = DateTime.Now; UpdateTimes(orig_application.Times, orig_application.SubEvent.Times); AssetHelpers helper = new AssetHelpers(db); helper.UpdateApplicatedAssets(orig_application.ApplicatedAssets, new_application.ApplicatedAssets); //foreach (ApplicatedAsset asset in new_application.ApplicatedAssets) //{ // if (asset.Id == 0) // asset.Id = db.GenerateIdFor(IdentityForTPC.ASSET_BASE); // orig_application.ApplicatedAssets.Add(asset); // asset.AssetApplicationId = orig_application.Id; //} }
public void NewAssetApplication(AssetApplication application, SubEvent sub_event, bool no_add = true, bool save = false) { application.Id = db.GenerateIdFor(IdentityForTPC.APPLICATION); application.ApplicantUserName = sub_event.Event.ChiefEventOrganizerId; application.ApplicatedDate = sub_event.Date; application.ClubId = sub_event.Event.ClubId; application.Date = DateTime.Now; application.Status = Application.NOT_SUBMITTED; application.SubEvent = sub_event; application.Times = sub_event.Times; foreach (ApplicatedAsset asset in application.ApplicatedAssets) { asset.Id = db.GenerateIdFor(IdentityForTPC.ASSET_BASE); asset.AssetApplicationId = application.Id; } if (!no_add) sub_event.AssetApplications.Add(application); if (save) db.SaveChanges(); }