private async Task <PackageCityViewModel> UploadOnly(string folder, PackageCityViewModel model)
        {
            ////if (model.ImageFile != null && model.ImageFile.Length > 0)
            ////{
            ////    try
            ////    {
            ////        if (!Directory.Exists(path))
            ////        {
            ////            DirectoryInfo di = Directory.CreateDirectory(path);
            ////        }

            ////        var fileName = $"{Guid.NewGuid().ToString()}{Path.GetExtension(model.ImageFile.FileName)}";
            ////        var filePath = Path.Combine(path, fileName);
            ////        using (var fileStream = new FileStream(filePath, FileMode.Create))
            ////        {
            ////            await model.ImageFile.CopyToAsync(fileStream);
            ////        }

            ////        model.Image = fileName;
            ////    }
            ////    catch (Exception ex)
            ////    {
            ////        var msg = ex.ToString();
            ////    }
            ////}
            model.Image = await this.UploadImageBlobStorage(folder, model.ImageFile);

            return(model);
        }
        public async Task <ActionResult> Manage(PackageCityViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var record = this.Mapper.Map <PackageCityModel>(model);
                if (model.Id == 0)
                {
                    if (model.ImageFile != null)
                    {
                        model = await this.UploadOnly("images/City", model);
                    }

                    record.Image = model.Image;
                    record.SetAuditInfo(0);
                    await this.city.InsertAsync(record);

                    if (!this.IsAjaxRequest())
                    {
                        this.ShowMessage(Messages.SavedSuccessfully);
                    }
                }
                else
                {
                    if (model.ImageFile != null)
                    {
                        model = await this.UploadOnly("images/City", model);
                    }

                    record.Image = model.Image;
                    record.UpdateAuditInfo(0);
                    await this.city.UpdateAsync(record);

                    if (!this.IsAjaxRequest())
                    {
                        this.ShowMessage(Messages.UpdateSuccessfully);
                    }
                }

                if (this.IsAjaxRequest())
                {
                    return(this.Json(new { success = true, Name = model.Name, Id = record.Id.ToString(), CityDescription = model.CityDescription }));
                }

                return(this.RedirectToRoute(Constants.RouteArea, new { controller = "city", action = "index", area = Constants.AreaAdmin }));
            }

            return(this.View(model));
        }
        public async Task <ActionResult> Manage(int id)
        {
            var model = new PackageCityViewModel();

            if (id > 0)
            {
                var record = await this.city.GetByIdAsync(id);

                //// model.States = (await this.masterService.GetPackageCountryListAsync(string.Empty, 1, model.CountryId, model.CountryId.ToString())).ToSelectList();
                model          = this.Mapper.Map <PackageCityViewModel>(record);
                model.Coutries = (await this.masterService.GetPackageCountryListAsync(string.Empty, 1, record.CountryId)).ToSelectList();
                model.States   = (await this.masterService.GetPackageStateListAsync(string.Empty, 1, record.StateId)).ToSelectList();
            }

            if (this.IsAjaxRequest())
            {
                return(this.View("_city", model));
            }

            return(this.View(model));
            ////return this.IsAjaxRequest()
            ////   ? this.View("_city", model)
            ////   : this.View(model);
        }