Esempio n. 1
0
        public async Task <IActionResult> Create([FromForm] Country country)
        {
            try
            {
                country.NoticeTranslate = JsonSerializer.Deserialize <ICollection <NoticeTranslate> >(country.Notices);
                if (!ModelState.IsValid)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                    {
                        Status = "Error",
                        Messages = new Message[] {
                            new Message {
                                Lang_id = 1,
                                MessageLang = "Model state isn't valid!"
                            },
                            new Message {
                                Lang_id = 2,
                                MessageLang = "Состояние модели недействительно!"
                            },
                            new Message {
                                Lang_id = 3,
                                MessageLang = "Model vəziyyəti etibarsızdır!"
                            }
                        }
                    }));
                }
                ValidateModel res = country.Photo.PhotoValidate();
                if (!res.Success)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, res.Response));
                }
                ValidateModel res2 = country.FlagPhoto.PhotoValidate();
                if (!res2.Success)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, res.Response));
                }
                string folder   = Path.Combine("Site", "images", "countries");
                string fileName = await country.Photo.SaveImage(_env.WebRootPath, folder);

                country.Image = fileName;
                fileName      = await country.FlagPhoto.SaveImage(_env.WebRootPath, folder);

                country.BgImage = fileName;
                _countryContext.Add(country);

                foreach (NoticeTranslate item in country.NoticeTranslate)
                {
                    item.CountryId = country.Id;
                    _noticeContext.Add(item);
                }
                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> PutAsync(int id, [FromForm] Country country)
        {
            try
            {
                country.NoticeTranslate = JsonSerializer.Deserialize <ICollection <NoticeTranslate> >(country.Notices);
                if (!ModelState.IsValid)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                    {
                        Status = "Error",
                        Messages = new Message[] {
                            new Message {
                                Lang_id = 1,
                                MessageLang = "Model state isn't valid!"
                            },
                            new Message {
                                Lang_id = 2,
                                MessageLang = "Состояние модели недействительно!"
                            },
                            new Message {
                                Lang_id = 3,
                                MessageLang = "Model vəziyyəti etibarsızdır!"
                            }
                        }
                    }));
                }
                Country db_country = _countryContext.GetWithId(id);
                if (db_country == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                    {
                        Status = "Error",
                        Messages = new Message[] {
                            new Message {
                                Lang_id = 1,
                                MessageLang = "Model state isn't valid!"
                            },
                            new Message {
                                Lang_id = 2,
                                MessageLang = "Состояние модели недействительно!"
                            },
                            new Message {
                                Lang_id = 3,
                                MessageLang = "Model vəziyyəti etibarsızdır!"
                            }
                        }
                    }));
                }
                if (country.Photo != null)
                {
                    ValidateModel res = country.Photo.PhotoValidate();
                    if (!res.Success)
                    {
                        return(StatusCode(StatusCodes.Status500InternalServerError, res.Response));
                    }

                    string folder   = Path.Combine("Site", "images", "countries");
                    string fileName = await country.Photo.SaveImage(_env.WebRootPath, folder);

                    db_country.Image = fileName;
                }

                if (country.FlagPhoto != null)
                {
                    ValidateModel res = country.FlagPhoto.PhotoValidate();
                    if (!res.Success)
                    {
                        return(StatusCode(StatusCodes.Status500InternalServerError, res.Response));
                    }

                    string folder   = Path.Combine("Site", "images", "countries");
                    string fileName = await country.FlagPhoto.SaveImage(_env.WebRootPath, folder);

                    db_country.BgImage = fileName;
                }
                db_country.Name      = country.Name;
                db_country.Value     = country.Value;
                db_country.IsActived = country.IsActived;
                db_country.Wallet    = country.Wallet;
                _countryContext.Update(db_country);
                foreach (NoticeTranslate item in country.NoticeTranslate)
                {
                    NoticeTranslate db_noticeTranslate = _noticeContext.GetWithId(item.Id);
                    db_noticeTranslate.Name = item.Name;
                    _noticeContext.Update(db_noticeTranslate);
                }
                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Post([FromForm] Cargo cargo)
        {
            try
            {
                AppUser user;
                if (!ModelState.IsValid)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                    {
                        Status = "Error",
                        Messages = new Message[] {
                            new Message {
                                Lang_id = 1,
                                MessageLang = "Model state isn't valid!"
                            },
                            new Message {
                                Lang_id = 2,
                                MessageLang = "Состояние модели недействительно!"
                            },
                            new Message {
                                Lang_id = 3,
                                MessageLang = "Model vəziyyəti etibarsızdır!"
                            }
                        }
                    }));
                }
                if (cargo.UserId != null)
                {
                    user = _user.Users.Where(u => u.Id == cargo.UserId).FirstOrDefault();
                    if (user == null)
                    {
                        return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                        {
                            Status = "Error",
                            Messages = new Message[] {
                                new Message {
                                    Lang_id = 1,
                                    MessageLang = "Model state isn't valid!"
                                },
                                new Message {
                                    Lang_id = 2,
                                    MessageLang = "Состояние модели недействительно!"
                                },
                                new Message {
                                    Lang_id = 3,
                                    MessageLang = "Model vəziyyəti etibarsızdır!"
                                }
                            }
                        }));
                    }
                }
                else
                {
                    user = _user.Users.Where(u => u.CamexId == cargo.CamexId).FirstOrDefault();
                    if (user == null)
                    {
                        return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                        {
                            Status = "Error",
                            Messages = new Message[] {
                                new Message {
                                    Lang_id = 1,
                                    MessageLang = "Model state isn't valid!"
                                },
                                new Message {
                                    Lang_id = 2,
                                    MessageLang = "Состояние модели недействительно!"
                                },
                                new Message {
                                    Lang_id = 3,
                                    MessageLang = "Model vəziyyəti etibarsızdır!"
                                }
                            }
                        }));
                    }
                }
                if (cargo.Photo != null)
                {
                    ValidateModel res = cargo.Photo.PhotoValidate();
                    if (!res.Success)
                    {
                        return(StatusCode(StatusCodes.Status500InternalServerError, res.Response));
                    }
                    string folder   = Path.Combine("Site", "images", "statements");
                    string fileName = await cargo.Photo.SaveImage(_env.WebRootPath, folder);

                    cargo.Image    = fileName;
                    cargo.StatusId = _statusContext.GetWithStatement("InAnbar").Id;
                }
                else
                {
                    cargo.StatusId = _statusContext.GetWithStatement("WaitingInvoice").Id;
                }
                cargo.IsActived  = true;
                cargo.OfficeId   = user.OfficeId;
                cargo.UserId     = user.Id;
                cargo.TrackCamex = Guid.NewGuid().ToString() + user.CamexId;


                _cargoContext.Add(cargo);

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> PutAsync(int id, [FromForm] Cargo cargo)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                    {
                        Status = "Error",
                        Messages = new Message[] {
                            new Message {
                                Lang_id = 1,
                                MessageLang = "Model state isn't valid!"
                            },
                            new Message {
                                Lang_id = 2,
                                MessageLang = "Состояние модели недействительно!"
                            },
                            new Message {
                                Lang_id = 3,
                                MessageLang = "Model vəziyyəti etibarsızdır!"
                            }
                        }
                    }));
                }
                Cargo db_cargo = _cargoContext.GetWithId(id);
                if (db_cargo == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                    {
                        Status = "Error",
                        Messages = new Message[] {
                            new Message {
                                Lang_id = 1,
                                MessageLang = "Model state isn't valid!"
                            },
                            new Message {
                                Lang_id = 2,
                                MessageLang = "Состояние модели недействительно!"
                            },
                            new Message {
                                Lang_id = 3,
                                MessageLang = "Model vəziyyəti etibarsızdır!"
                            }
                        }
                    }));
                }

                if (db_cargo.Image == null || db_cargo.Image == "")
                {
                    ValidateModel res = cargo.Photo.PhotoValidate();
                    if (!res.Success)
                    {
                        return(StatusCode(StatusCodes.Status500InternalServerError, res.Response));
                    }
                    string folder   = Path.Combine("Site", "images", "statements");
                    string fileName = await cargo.Photo.SaveImage(_env.WebRootPath, folder);

                    db_cargo.Image = fileName;
                }
                db_cargo.Name         = cargo.Name;
                db_cargo.ProductId    = cargo.ProductId;
                db_cargo.Price        = cargo.Price;
                db_cargo.CountryId    = cargo.CountryId;
                db_cargo.Count        = cargo.Count;
                db_cargo.Notice       = cargo.Notice;
                db_cargo.ModifiedDate = DateTime.Now;
                db_cargo.StatusId     = _statusContext.GetWithStatement("InAnbar").Id;
                _cargoContext.Update(db_cargo);
                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
        public async Task <IActionResult> PutAsync(int id, [FromForm] Bio bio)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                    {
                        Status = "Error",
                        Messages = new Message[] {
                            new Message {
                                Lang_id = 1,
                                MessageLang = "Model state isn't valid!"
                            },
                            new Message {
                                Lang_id = 2,
                                MessageLang = "Состояние модели недействительно!"
                            },
                            new Message {
                                Lang_id = 3,
                                MessageLang = "Model vəziyyəti etibarsızdır!"
                            }
                        }
                    }));
                }
                Bio db_bio = _bioContext.GetWithId(id);
                if (db_bio == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                    {
                        Status = "Error",
                        Messages = new Message[] {
                            new Message {
                                Lang_id = 1,
                                MessageLang = "Model state isn't valid!"
                            },
                            new Message {
                                Lang_id = 2,
                                MessageLang = "Состояние модели недействительно!"
                            },
                            new Message {
                                Lang_id = 3,
                                MessageLang = "Model vəziyyəti etibarsızdır!"
                            }
                        }
                    }));
                }
                if (bio.Photo != null)
                {
                    ValidateModel res = bio.Photo.PhotoValidate();
                    if (!res.Success)
                    {
                        return(StatusCode(StatusCodes.Status500InternalServerError, res.Response));
                    }

                    string folder   = Path.Combine("Site", "images", "bio");
                    string fileName = await bio.Photo.SaveImage(_env.WebRootPath, folder);

                    db_bio.LogoNavbar = fileName;
                }

                if (db_bio.Photo2 != null)
                {
                    ValidateModel res = bio.Photo2.PhotoValidate();
                    if (!res.Success)
                    {
                        return(StatusCode(StatusCodes.Status500InternalServerError, res.Response));
                    }

                    string folder   = Path.Combine("Site", "images", "bio");
                    string fileName = await bio.Photo2.SaveImage(_env.WebRootPath, folder);

                    db_bio.LogoFooter = fileName;
                }
                db_bio.PageTitle      = bio.PageTitle;
                db_bio.ShortDescAz    = bio.ShortDescAz;
                db_bio.ShortDescRus   = bio.ShortDescRus;
                db_bio.ShortDescEng   = bio.ShortDescEng;
                db_bio.SliderTitleAz  = bio.SliderTitleAz;
                db_bio.SliderTitleRus = bio.SliderTitleRus;
                db_bio.SliderTitleEng = bio.SliderTitleEng;
                db_bio.CallCenter     = bio.CallCenter;

                _bioContext.Update(db_bio);
                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }