public async Task <ActionResult> Add(TechnicalStaffViewModel technicalStaffModel)
        {
            var canAddTechnicalStaff = await _participationService
                                       .CanAddTechnicalStaff(technicalStaffModel.ParticipationId, Convert.ToInt32(User.Identity.Name));

            if (!canAddTechnicalStaff)
            {
                ModelState.AddModelError("", "امکان درج کادر فنی جدید وجود ندارد.");
                return(this.JsonValidationErrors());
            }

            var tmpPath = Server.MapPath("~/App_Data/tmp/");

            var fullName = string.Format("{0}-{1}", technicalStaffModel.FirstName, technicalStaffModel.LastName).ApplyCorrectYeKe();

            if (technicalStaffModel.Id == 0)
            {
                var userImagePath = Server.MapPath("~/App_Data/TechnicalStaff_Image/");

                await
                CopyFileAsync(tmpPath + technicalStaffModel.Image,
                              userImagePath + string.Format("{0}-{1}", fullName, technicalStaffModel.Image));

                technicalStaffModel.Image = string.Format("{0}-{1}", fullName, technicalStaffModel.Image);
            }

            var technicalStaff = new DomainClasses.TechnicalStaff
            {
                FirstName    = technicalStaffModel.FirstName,
                BirthDate    = technicalStaffModel.BirthDate,
                FatherName   = technicalStaffModel.FatherName,
                Image        = technicalStaffModel.Image,
                LastName     = technicalStaffModel.LastName,
                NationalCode = technicalStaffModel.NationalCode,
                Id           = technicalStaffModel.Id
            };

            var similarParticipationIds =
                await _participationService.GetSimilarParticipationSport(technicalStaffModel.ParticipationId,
                                                                         Convert.ToInt32(User.Identity.Name));

            foreach (var participationId in similarParticipationIds)
            {
                _technicalStaffService.Add(technicalStaff, participationId, technicalStaffModel.TechnicalStaffRoleId);
            }

            await _dbContext.SaveChangesAsync();

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Beispiel #2
0
        // GET: TechnicalStaff/UserPanel
        public async Task <ActionResult> Add(TechnicalStaffViewModel technicalStaffModel, int competitionId)
        {
            var canAddTechnicalStaff = await _competitionService
                                       .CanAddCommonTechnicalStaff(competitionId, Convert.ToInt32(User.Identity.Name));

            if (!canAddTechnicalStaff)
            {
                ModelState.AddModelError("", "امکان درج کادر اجرایی جدید وجود ندارد.");
                return(this.JsonValidationErrors());
            }


            var tmpPath = Server.MapPath("~/App_Data/tmp/");


            var fullName = string.Format("{0}-{1}", technicalStaffModel.FirstName, technicalStaffModel.LastName).ApplyCorrectYeKe();


            var userImagePath = Server.MapPath("~/App_Data/TechnicalStaff_Image/");

            await
            CopyFileAsync(tmpPath + technicalStaffModel.Image,
                          userImagePath + string.Format("{0}-{1}", fullName, technicalStaffModel.Image));

            technicalStaffModel.Image = string.Format("{0}-{1}", fullName, technicalStaffModel.Image);


            var technicalStaff = new DomainClasses.TechnicalStaff
            {
                FirstName    = technicalStaffModel.FirstName,
                BirthDate    = technicalStaffModel.BirthDate,
                FatherName   = technicalStaffModel.FatherName,
                Image        = technicalStaffModel.Image,
                LastName     = technicalStaffModel.LastName,
                NationalCode = technicalStaffModel.NationalCode,
                Id           = technicalStaffModel.Id,
                MobileNumber = technicalStaffModel.MobileNumber
            };

            _commonTechnicalStaffService.Add(technicalStaff, Convert.ToInt32(User.Identity.Name),
                                             competitionId,
                                             technicalStaffModel.TechnicalStaffRoleId);

            await _dbContext.SaveChangesAsync();

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Beispiel #3
0
        public async Task <ActionResult> Edit(TechnicalStaffViewModel technicalStaffModel)
        {
            var selectedTechnicalStaff = await _technicalStaffService.Find(technicalStaffModel.Id);

            var userId = Convert.ToInt32(User.Identity.Name);

            if (selectedTechnicalStaff.IsApproved == null || selectedTechnicalStaff.IsApproved == true)
            {
                var canEdit = await _competitionService.CanEditCommonTechnicalStaff(technicalStaffModel.CompetitionId, userId);

                if (!canEdit)
                {
                    ModelState.AddModelError("", "امکان ویرایش کادر اجرایی وجود ندارد.");
                    return(this.JsonValidationErrors());
                }
            }
            else
            {
                var canEdit = await _competitionService.CanEditRejectedCommonTechnicalStaff(technicalStaffModel.CompetitionId, userId);

                if (!canEdit)
                {
                    ModelState.AddModelError("", "امکان ویرایش کادر اجرایی وجود ندارد.");
                    return(this.JsonValidationErrors());
                }
            }


            if (technicalStaffModel.Image != selectedTechnicalStaff.Image)
            {
                var tmpPath = Server.MapPath("~/App_Data/tmp/");

                var fullName = string.Format("{0}-{1}", technicalStaffModel.FirstName, technicalStaffModel.LastName).ApplyCorrectYeKe();

                var userImagePath = Server.MapPath("~/App_Data/TechnicalStaff_Image/");

                await
                CopyFileAsync(tmpPath + technicalStaffModel.Image,
                              userImagePath + string.Format("{0}-{1}", fullName, technicalStaffModel.Image));

                try
                {
                    System.IO.File.Delete(userImagePath + selectedTechnicalStaff.Image);
                }
                catch (Exception)
                {
                }

                selectedTechnicalStaff.Image = string.Format("{0}-{1}", fullName, technicalStaffModel.Image);
            }

            selectedTechnicalStaff.FirstName    = technicalStaffModel.FirstName;
            selectedTechnicalStaff.LastName     = technicalStaffModel.LastName;
            selectedTechnicalStaff.FatherName   = technicalStaffModel.FatherName;
            selectedTechnicalStaff.NationalCode = technicalStaffModel.NationalCode;
            selectedTechnicalStaff.BirthDate    = technicalStaffModel.BirthDate;
            selectedTechnicalStaff.MobileNumber = technicalStaffModel.MobileNumber;


            selectedTechnicalStaff.IsApproved = null;


            var selectedCompetitionTechnicalStaff = await _commonTechnicalStaffService.GetCompetitionTechnicalStaff(technicalStaffModel.Id, Convert.ToInt32(User.Identity.Name));


            if (technicalStaffModel.TechnicalStaffRoleId != selectedCompetitionTechnicalStaff.TechnicalStaffRoleId)
            {
                selectedCompetitionTechnicalStaff.TechnicalStaffRoleId = technicalStaffModel.TechnicalStaffRoleId;
            }


            await _dbContext.SaveChangesAsync();

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }