public ActionResult Create(AppVersionViewModel collection) { try { if (ModelState.IsValid) { var model = _mapper.Map <AppVersion>(collection); model.CreatorId = LogedInAdmin.Id; model.CreatedAt = DateTime.Now; var id = _appVersionService.Insert(model); if (collection.LastVersionCheck) { var registeredClient = _registeredClientService.Single(new RegisteredClient { Id = collection.ClientId }); registeredClient.LastStableVersion = id; _registeredClientService.Update(registeredClient); } return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, GeneralMessages.DefectiveEntry); } catch (Exception ex) { _logger.Error(ex); if (ex.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, GeneralMessages.Duplicated); } else { if (ex.InnerException != null && ex.InnerException.Source.Equals(GeneralMessages.ExceptionSource)) { ModelState.AddModelError(string.Empty, ex.Message); } else { ModelState.AddModelError(string.Empty, GeneralMessages.UnexpectedError); } } } var client = _mapper.Map <List <RegisteredClientViewModel> >(_registeredClientService.Find(new RegisteredClient())); ViewData["client"] = new SelectList(client, "Id", "Name"); return(View(collection)); }
public ActionResult Edit(RegisteredClientViewModel collection) { try { if (ModelState.IsValid) { var model = _mapper.Map <RegisteredClient>(collection); _registeredClientService.Update(model); return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, GeneralMessages.DefectiveEntry); return(View(collection)); } catch (Exception ex) { _logger.Error(ex); if (ex.InnerException != null && ex.InnerException.Source.Equals(GeneralMessages.ExceptionSource)) { ModelState.AddModelError(string.Empty, ex.Message); } else { ModelState.AddModelError(string.Empty, GeneralMessages.UnexpectedError); } return(View(collection)); } }