Exemplo n.º 1
0
        public async Task<ActionResult> Add(CompetitionViewModel competitionModel)
        {
            if (!string.IsNullOrEmpty(competitionModel.LogoImage))
            {
                var tmpPath = Server.MapPath("~/App_Data/tmp/");
                var logoImagePath = Server.MapPath("~/App_Data/Logo_Image/");

                await
                    CopyFileAsync(tmpPath + competitionModel.LogoImage,
                        logoImagePath + competitionModel.LogoImage);
            }

            if (competitionModel.IsRegisterActive && competitionModel.IsPrintCardActive == false)
            {
                competitionModel.PrintCardStartDate = competitionModel.RegisterEndDate.Value.AddDays(3);
            }

            var competition = new DomainClasses.Competition
            {
                Name = competitionModel.Name,
                ReadyStartDate = competitionModel.ReadyStartDate,
                ReadyEndDate = competitionModel.ReadyEndDate,
                RegisterStartDate = competitionModel.RegisterStartDate,
                RegisterEndDate = competitionModel.RegisterEndDate,
                IsReadyActive = competitionModel.IsReadyActive,
                IsRegisterActive = competitionModel.IsRegisterActive,
                IsPrintCardActive = competitionModel.IsPrintCardActive,
                LogoImage = competitionModel.LogoImage,
                PrintCardEndDate = competitionModel.PrintCardEndDate,
                PrintCardStartDate = competitionModel.PrintCardStartDate,
                Rule = competitionModel.Rule.ToSafeHtml(),
                MaxCommonTechnicalStaffs = competitionModel.MaxCommonTechnicalStaffs
            };

            _competitionService.Add(competition);

            await _dbContext.SaveChangesAsync();

            return Json(new { id = competition.Id });
        }
Exemplo n.º 2
0
        public async Task<ActionResult> Edit(CompetitionViewModel competitionModel)
        {
            //if (!ModelState.IsValid) throw null;


            var selectedCompetition = await _competitionService.Find(competitionModel.Id);

            if (selectedCompetition.LogoImage != competitionModel.LogoImage)
            {
                var tmpPath = Server.MapPath("~/App_Data/tmp/");
                var logoImagePath = Server.MapPath("~/App_Data/Logo_Image/");
                await
                    CopyFileAsync(tmpPath + competitionModel.LogoImage,
                        logoImagePath + competitionModel.LogoImage);

                try
                {
                    System.IO.File.Delete(logoImagePath + selectedCompetition.LogoImage);
                }
                catch (Exception)
                {

                }
            }

            selectedCompetition.IsPrintCardActive = competitionModel.IsPrintCardActive;
            selectedCompetition.IsReadyActive = competitionModel.IsReadyActive;
            selectedCompetition.IsRegisterActive = competitionModel.IsRegisterActive;

            selectedCompetition.LogoImage = competitionModel.LogoImage;

            selectedCompetition.Name = competitionModel.Name;
            selectedCompetition.PrintCardEndDate = competitionModel.PrintCardEndDate;
            selectedCompetition.PrintCardStartDate = competitionModel.PrintCardStartDate;
            selectedCompetition.ReadyEndDate = competitionModel.ReadyEndDate;
            selectedCompetition.ReadyStartDate = competitionModel.ReadyStartDate;

            selectedCompetition.RegisterStartDate = competitionModel.RegisterStartDate;
            selectedCompetition.RegisterEndDate = competitionModel.RegisterEndDate;
            selectedCompetition.Rule = competitionModel.Rule.ToSafeHtml();

            selectedCompetition.MaxCommonTechnicalStaffs = competitionModel.MaxCommonTechnicalStaffs;


            await _dbContext.SaveChangesAsync();

            return new HttpStatusCodeResult(HttpStatusCode.OK);
        }