public ActionResult Create(ProvinceViewModel province, string returnUrl)
        {
            ActionResult action;

            try
            {
                if (!ModelState.IsValid)
                {
                    ModelState.AddModelError("", MessageUI.ErrorMessage);
                    return(View(province));
                }

                var province1 = Mapper.Map <ProvinceViewModel, Province>(province);
                _provinceService.Create(province1);
                Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.Provinces)));
                if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\"))
                {
                    action = RedirectToAction("Index");
                }
                else
                {
                    action = Redirect(returnUrl);
                }
            }
            catch (Exception exception1)
            {
                var exception = exception1;
                ExtentionUtils.Log(string.Concat("Province.Create: ", exception.Message));
                return(View(province));
            }
            return(action);
        }
        public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            IProvinceService service = testServer.Host.Services.GetService(typeof(IProvinceService)) as IProvinceService;
            var model = new ApiProvinceServerRequestModel();

            model.SetProperties(1, "B");
            CreateResponse <ApiProvinceServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.ProvinceDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiProvinceServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
Example #3
0
        private void collectAndInsertOrUpdateProvinces()
        {
            var provinces = collectToRajaOngkir <IList <ApiRajaOngkirProvinceResponseDto> >("province");

            foreach (var provinceInputDto in provinces)
            {
                if (!_provinceService.Exist(provinceInputDto.ProvinceId))
                {
                    _provinceService.Create(new CreateProvinceInputDto {
                        IdRajaOngkir = provinceInputDto.ProvinceId, Code = provinceInputDto.ProvinceName, Name = provinceInputDto.ProvinceName
                    });
                }
            }
        }
Example #4
0
 public ActionResult Create(ProvinceViewModel model)
 {
     if (ModelState.IsValid)
     {
         var Province = new Province();
         AutoMapper.Mapper.Map(model, Province);
         SetModifier(Province);
         ProvinceService.Create(Province);
         Province.ProvinceId = Province.Id.ToString();
         ProvinceService.Update(Province);
         TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess;
         if (Request["IsPopup"] != null && Request["IsPopup"].ToString().ToLower().Equals("true"))
         {
             return(RedirectToAction("_ClosePopup", "Home", new { area = "", FunctionCallback = "updateProvince(" + Province.Id + ", '" + Helpers.Common.Capitalize(string.Format("{0} {1}", Province.Type, Province.Name)) + "')" }));
         }
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Example #5
0
        public virtual ActionResult CreateProvince(ProvinceAddViewModel provinceViewModel)
        {
            var province = new Province {
                Name = provinceViewModel.Name
            };

            _provinceService.Create(province);
            if (_unitOfWork.SaveAllChanges() > 0)
            {
                return(PartialView(viewName: MVC.admin.Shared.Views._alert, model: new AlertViewModel {
                    Alert = AlertOperation.SurveyOperation(StatusOperation.SuccsessInsert), Status = AlertMode.success
                }));
            }
            else
            {
                return(PartialView(viewName: MVC.admin.Shared.Views._alert, model: new AlertViewModel {
                    Alert = AlertOperation.SurveyOperation(StatusOperation.FailInsert), Status = AlertMode.warning
                }));
            }
        }
        public async Task <ActionResult <ProvinceDetail_ProvinceDTO> > Create([FromBody] ProvinceDetail_ProvinceDTO ProvinceDetail_ProvinceDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new MessageException(ModelState);
            }

            Province Province = ConvertDTOToEntity(ProvinceDetail_ProvinceDTO);

            Province = await ProvinceService.Create(Province);

            ProvinceDetail_ProvinceDTO = new ProvinceDetail_ProvinceDTO(Province);
            if (Province.IsValidated)
            {
                return(ProvinceDetail_ProvinceDTO);
            }
            else
            {
                return(BadRequest(ProvinceDetail_ProvinceDTO));
            }
        }