Exemplo n.º 1
0
 public ActionResult Edit(CampusViewModel viewModel)
 {
     try
     {
         var    validateName      = _campusService.GetCampusDuplicate(viewModel.ID, viewModel.Name.Trim());
         string MatchPhonePattern = @"^\(?([0-9]{3})\)?[-.●]?([0-9]{3})[-.●]?([0-9]{4})$";
         Regex  rx = new Regex(MatchPhonePattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
         if (!rx.IsMatch(viewModel.Telephone.Trim()))
         {
             ModelState.AddModelError("Telephone", "Telephone must numbers");
             return(View(viewModel));
         }
         if (validateName != null)
         {
             ModelState.AddModelError("Name", "Campus Name already exists");
         }
         if (ModelState.IsValid)
         {
             // TODO: Add update logic here
             var campus = _campusService.GetById(viewModel.ID);
             campus.Name      = viewModel.Name.Trim();
             campus.Address   = viewModel.Address;
             campus.Telephone = viewModel.Telephone.Trim();
             campus.Active    = viewModel.Active;
             _campusService.Update(campus);
             _campusService.SaveChanges();
             SetAlert("Update Campus success", "success");
             return(RedirectToAction("Index"));
         }
     }catch (Exception e)
     {
         SetAlert("Update Campus error", "error");
     }
     return(View(viewModel));
 }
Exemplo n.º 2
0
        public async Task <ActionResult> Edit(int id, CampusViewModel campusViewModel)
        {
            var temp = await _campusService.FindById(id);

            var existinCampus = await _campusService.FindByCode(campusViewModel.Code);

            if (existinCampus == null || temp.Code == existinCampus.Code)
            {
                var campus = new Campus
                {
                    Name = campusViewModel.Name,
                    Code = campusViewModel.Code
                };
                await _campusService.Update(id, campus);

                return(Ok());
            }
            else
            {
                return(BadRequest("Ya existe un campus con este codigo"));
            }
        }
 public async Task <ActionResult <CampusForReturnDto> > Update(CampuseForCreationDto updateDto)
 {
     return(await campuseService.Update(updateDto));
 }