public ActionResult Index(Guid id)
        {
            ProjectDetailPromoterViewModel result = new ProjectDetailPromoterViewModel();
            List <ProjectDetailPromoter>   projectDetailPromoters = db.ProjectDetailPromoters
                                                                    .Where(p => p.ProjectDetailId == id && p.IsDeleted == false).OrderByDescending(p => p.CreationDate)
                                                                    .ToList();


            var projectDetail = db.ProjectDetails.Find(id);

            if (projectDetail != null)
            {
                ViewBag.UserId = new SelectList(db.Users.Where(c => c.Role.Name == "promoter" && c.CityId == projectDetail.Store.CityId), "Id",
                                                "FullName");

                ViewBag.Title = "فهرست پروموترهای پروژه " + projectDetail.Project.Title + " فروشگاه " +
                                projectDetail.Store.Title;

                result.ProjectDetailPromoters = projectDetailPromoters;
                result.StartDate            = projectDetail.Project.StartDateStr;
                result.EndDate              = projectDetail.Project.EndDateStr;
                result.SalaryPerHour        = projectDetail.SalaryPerHourStr;
                result.TransportationAmount = projectDetail.TransportationAmountStr;
                result.StartHour            = projectDetail.StartHourStr;
                result.FinishHour           = projectDetail.FinishHourStr;
                result.ProjectDetailId      = id;
            }

            return(View(result));
        }
        public ActionResult CreatePromoter(ProjectDetailPromoterViewModel input)
        {
            if (db.ProjectDetailPromoters.Any(c =>
                                              c.UserId == input.UserId && c.ProjectDetailId == input.ProjectDetailId && c.IsDeleted == false))
            {
                TempData["invalidPromoter"] = "پروموتر انتخابی قبلا برای این پروژه انتخاب شده است. پروموتر دیگری را انتخاب کنید.";
                return(RedirectToAction("index", new { id = input.ProjectDetailId }));
            }

            ProjectDetailPromoter projectDetailPromoter = new ProjectDetailPromoter()
            {
                Id              = Guid.NewGuid(),
                IsActive        = true,
                IsDeleted       = false,
                IsFullTime      = true,
                ProjectDetailId = input.ProjectDetailId,
                UserId          = input.UserId.Value,
                CreationDate    = DateTime.Now,
            };

            db.ProjectDetailPromoters.Add(projectDetailPromoter);

            var projectDetail = db.ProjectDetails.Find(input.ProjectDetailId);

            string totalTimeSpan = (projectDetail.Project.EndDate.Value - projectDetail.Project.StartDate).ToString();

            int totalDays = Convert.ToInt32(totalTimeSpan.Split('.')[0]);

            for (int i = 0; i <= totalDays; i++)
            {
                DailyPromoterPlan dailyPromoterPlan = new DailyPromoterPlan()
                {
                    Id = Guid.NewGuid(),
                    ProjectDetailPromoterId = projectDetailPromoter.Id,
                    ShiftDate    = projectDetail.Project.StartDate.AddDays(i),
                    CreationDate = DateTime.Now,
                    IsDeleted    = false,
                    IsActive     = true,
                };

                db.DailyPromoterPlans.Add(dailyPromoterPlan);
            }

            db.SaveChanges();
            return(RedirectToAction("index", new { id = input.ProjectDetailId }));
        }