Пример #1
0
        public async Task <string> UpdateAdminPromotional(UpdateAdminPromotionalDto UpdateAdminPromotionalDto)
        {
            DateTime Presentdate             = Convert.ToDateTime(GetPresentdate);
            DateTime Timezone                = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(Presentdate, TimeZoneInfo.Local.Id, UpdateAdminPromotionalDto.CountryTimezone);
            var      AdminPromotionalDetails = Repository.SingleOrDefault(x => x.Id == UpdateAdminPromotionalDto.PromotionalId);

            if (AdminPromotionalDetails.IsDefault == "0" || String.IsNullOrEmpty(AdminPromotionalDetails.IsDefault))
            {
                if (AdminPromotionalDetails.EndDate > Timezone && (AdminPromotionalDetails.StartDate > Timezone || UpdateAdminPromotionalDto.StartDate == AdminPromotionalDetails.StartDate))
                {
                    if (UpdateAdminPromotionalDto.EndDate > Timezone && UpdateAdminPromotionalDto.EndDate > UpdateAdminPromotionalDto.StartDate)
                    {
                        if (!string.IsNullOrEmpty(UpdateAdminPromotionalDto.Countries))
                        {
                            await _AdminPromotionalCountriesService.deleteAdminPromotional(UpdateAdminPromotionalDto.PromotionalId);

                            await _AdminPromotionalCountriesService.InsertAdminPromotionalCountriesDetails(UpdateAdminPromotionalDto.Countries, UpdateAdminPromotionalDto.PromotionalId);

                            AdminPromotionalDetails.Promotionalcountries = AdminPromotionalDetails.Promotionalcountries;
                        }
                        if (!string.IsNullOrEmpty(UpdateAdminPromotionalDto.EnglishImage))
                        {
                            AdminPromotionalDetails.EnglishImage = UpdateAdminPromotionalDto.EnglishImage;
                        }
                        if (!string.IsNullOrEmpty(UpdateAdminPromotionalDto.ArabicImage))
                        {
                            AdminPromotionalDetails.ArabicImage = UpdateAdminPromotionalDto.ArabicImage;
                        }
                        if (UpdateAdminPromotionalDto.AdminPromotionalURL != null)
                        {
                            AdminPromotionalDetails.PromotionalURL = UpdateAdminPromotionalDto.AdminPromotionalURL;
                        }
                        if (UpdateAdminPromotionalDto.AdminPromotionalDescription != null)
                        {
                            AdminPromotionalDetails.Promotionaldescription = UpdateAdminPromotionalDto.AdminPromotionalDescription;
                        }
                        if (!string.IsNullOrEmpty(UpdateAdminPromotionalDto.StartDate.ToString()))
                        {
                            AdminPromotionalDetails.StartDate = UpdateAdminPromotionalDto.StartDate;
                        }
                        if (!string.IsNullOrEmpty(UpdateAdminPromotionalDto.EndDate.ToString()))
                        {
                            AdminPromotionalDetails.EndDate = UpdateAdminPromotionalDto.EndDate;
                        }
                        if (!string.IsNullOrEmpty(UpdateAdminPromotionalDto.CountryTimezone.ToString()))
                        {
                            AdminPromotionalDetails.TimeZone = UpdateAdminPromotionalDto.CountryTimezone;
                        }
                        await Repository.UpdateAsync(AdminPromotionalDetails);

                        return("Admin Promotional updated successfully");
                    }
                    else if (UpdateAdminPromotionalDto.EndDate < Timezone)
                    {
                        return("Please select the end date is greater then present date");
                    }
                    else
                    {
                        return("Please select the end date is greater then start date.");
                    }
                }
                else if (AdminPromotionalDetails.EndDate < Timezone)
                {
                    return("Sorry you Admin Promotional was expired");
                }
                else
                {
                    return("Sorry you are not allowed to update, Admin Promotional is live now");
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(UpdateAdminPromotionalDto.EnglishImage))
                {
                    AdminPromotionalDetails.EnglishImage = UpdateAdminPromotionalDto.EnglishImage;
                }
                if (!string.IsNullOrEmpty(UpdateAdminPromotionalDto.ArabicImage))
                {
                    AdminPromotionalDetails.ArabicImage = UpdateAdminPromotionalDto.ArabicImage;
                }
                if (!string.IsNullOrEmpty(UpdateAdminPromotionalDto.AdminPromotionalURL))
                {
                    AdminPromotionalDetails.PromotionalURL = UpdateAdminPromotionalDto.AdminPromotionalURL;
                }
                if (!string.IsNullOrEmpty(UpdateAdminPromotionalDto.AdminPromotionalDescription))
                {
                    AdminPromotionalDetails.Promotionaldescription = UpdateAdminPromotionalDto.AdminPromotionalDescription;
                }
                await Repository.UpdateAsync(AdminPromotionalDetails);

                return("Admin Promotional updated successfully");
            }
        }
        public async Task <IActionResult> UpdateAdminPromotionals([FromBody] UpdateAdminPromotionalDto UpdateAdminPromotionalDto)
        {
            string AdminPromotionalupdatestatus = string.Empty;

            try
            {
                strImagePath = _configuration["FilePath:ImagePath"] + "AdminPromotional/";

                if (!Directory.Exists(strImagePath))
                {
                    Directory.CreateDirectory(strImagePath);
                }

                if (!String.IsNullOrEmpty(UpdateAdminPromotionalDto.EnglishImage))
                {
                    if (UpdateAdminPromotionalDto.EnglishImage.Substring(UpdateAdminPromotionalDto.EnglishImage.Length - 3) != "jpg")
                    {
                        if (!String.IsNullOrEmpty(UpdateAdminPromotionalDto.EnglishImage))
                        {
                            Byte[] EnglishimageByteData = Convert.FromBase64String(UpdateAdminPromotionalDto.EnglishImage);
                            var    Englishfs            = new BinaryWriter(new FileStream(strImagePath + AdminPromotionalEnglishImages + ".jpg", FileMode.Create, FileAccess.Write));
                            Englishfs.Write(EnglishimageByteData);
                            Englishfs.Close();
                            UpdateAdminPromotionalDto.EnglishImage = AdminPromotionalEnglishImages + ".jpg";
                        }
                    }
                    else
                    {
                        UpdateAdminPromotionalDto.EnglishImage = "";
                    }
                }
                else
                {
                    UpdateAdminPromotionalDto.EnglishImage = "";
                }
                if (!String.IsNullOrEmpty(UpdateAdminPromotionalDto.ArabicImage))
                {
                    if (UpdateAdminPromotionalDto.ArabicImage.Substring(UpdateAdminPromotionalDto.ArabicImage.Length - 3) != "jpg")
                    {
                        if (!String.IsNullOrEmpty(UpdateAdminPromotionalDto.ArabicImage))
                        {
                            Byte[] ArabicimageByteData = Convert.FromBase64String(UpdateAdminPromotionalDto.ArabicImage);
                            var    Arabicfs            = new BinaryWriter(new FileStream(strImagePath + AdminPromotionalArabicImages + ".jpg", FileMode.Create, FileAccess.Write));
                            Arabicfs.Write(ArabicimageByteData);
                            Arabicfs.Close();
                            UpdateAdminPromotionalDto.ArabicImage = AdminPromotionalArabicImages + ".jpg";
                        }
                    }
                    else
                    {
                        UpdateAdminPromotionalDto.ArabicImage = "";
                    }
                }
                else
                {
                    UpdateAdminPromotionalDto.ArabicImage = "";
                }
                AdminPromotionalupdatestatus = await _AdminPromotionalService.UpdateAdminPromotional(UpdateAdminPromotionalDto);

                if (AdminPromotionalupdatestatus == "Admin Promotional updated successfully")
                {
                    return(Ok(new GenericResultDto <string> {
                        Result = AdminPromotionalupdatestatus
                    }));
                }
                return(BadRequest(new GenericResultDto <string> {
                    Result = AdminPromotionalupdatestatus
                }));
            }

            catch (Exception err)
            {
                return(BadRequest(new GenericResultDto <string> {
                    Result = err.Message
                }));
            }
        }