コード例 #1
0
 public ActionResult OnBoard(int id)
 {
     try
     {
         var detail = db.RequirementDetails.Include(d => d.Resource).Include(d => d.Requirement).Where(d => d.RequirementDetailId == id).FirstOrDefault();
         var model  = new ResourceOnBoardModel
         {
             RequirementDetailId = detail.RequirementDetailId,
             RequirementId       = detail.RequirementId,
             ResourceId          = detail.ResourceId.Value,
             RecruiterId         = detail.RecruiterId,
             BuyRate             = detail.Requirement.HourlyBuyRate,
             BillingRate         = detail.Requirement.HourlyBillingRate,
             FinalRate           = detail.Requirement.HourlyBuyRate
         };
         var projectDetail = db.ProjectDetails.Where(p => p.RequirementId == model.RequirementId && p.ResourceId == model.ResourceId).FirstOrDefault();
         if (projectDetail != null)
         {
             model.ProjectStartDate = projectDetail.StartDate;
             model.ProjectEndDate   = projectDetail.EndDate;
             model.PlacementDate    = projectDetail.PlacementDate;
         }
         return(View(model));
     }
     catch (Exception exp)
     {
         Logger.LogException(exp);
         return(RedirectToAction("AppError", "Error"));
     }
 }
コード例 #2
0
        public ActionResult OnBoard([Bind(Include = "RequirementDetailId,ResourceId,RequirementId,RecruiterId,ProjectStartDate,ProjectEndDate,PlacementDate,FinalRate")] ResourceOnBoardModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var projectDetail = db.ProjectDetails.Where(p => p.RequirementId == model.RequirementId && p.ResourceId == model.ResourceId).FirstOrDefault();
                    var requirement   = db.Requirements.Find(model.RequirementId);
                    // update project details.
                    if (projectDetail != null)
                    {
                        projectDetail.StartDate       = model.ProjectStartDate.Value;
                        projectDetail.EndDate         = model.ProjectEndDate;
                        projectDetail.PlacementDate   = model.PlacementDate.Value;
                        db.Entry(projectDetail).State = EntityState.Modified;
                    }
                    else
                    {
                        projectDetail = new ProjectDetail
                        {
                            RequirementId    = model.RequirementId,
                            ResourceId       = model.ResourceId,
                            RecruiterId      = model.RecruiterId,
                            StartDate        = model.ProjectStartDate.Value,
                            EndDate          = model.ProjectEndDate,
                            PlacementDate    = model.PlacementDate.Value,
                            AccountManagerId = requirement.AccountManagerId
                        };
                        db.ProjectDetails.Add(projectDetail);
                    }
                    db.SaveChanges();

                    //update final buy rate in requirement
                    requirement.RequirementId    = model.RequirementId;
                    requirement.HourlyBuyRate    = model.FinalRate;
                    requirement.UpdatedBy        = User.Identity.GetUserId();
                    requirement.UpdatedTimestamp = DateTime.Now;
                    db.Requirements.Attach(requirement);
                    db.Entry(requirement).Property(r => r.HourlyBuyRate).IsModified    = true;
                    db.Entry(requirement).Property(r => r.UpdatedBy).IsModified        = true;
                    db.Entry(requirement).Property(r => r.UpdatedTimestamp).IsModified = true;
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();

                    //update project end date and client for the resource.
                    var resource = new Resource();
                    resource.ResourceId     = model.ResourceId;
                    resource.ClientId       = requirement.Tier1ClientId;
                    resource.ProjectEndDate = model.ProjectEndDate;
                    resource.UpdatedBy      = User.Identity.GetUserId();
                    resource.UpdatedTime    = DateTime.Now;
                    db.Resources.Attach(resource);
                    db.Entry(resource).Property(r => r.ProjectEndDate).IsModified = true;
                    db.Entry(resource).Property(r => r.UpdatedBy).IsModified      = true;
                    db.Entry(resource).Property(r => r.UpdatedTime).IsModified    = true;
                    db.Entry(resource).Property(r => r.ClientId).IsModified       = true;
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();

                    return(RedirectToAction("Index", "Requirement", new { requirementId = model.RequirementId }));
                }
                return(View(model));
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                Logger.LogMessage(exceptionMessage);
                return(RedirectToAction("AppError", "Error"));
            }
            catch (Exception exp)
            {
                Logger.LogException(exp);
                return(RedirectToAction("AppError", "Error"));
            }
        }