public void Create(AspNetUserModel model, out string id) { try { _unitOfWork.BeginTransaction(); id = ""; var passwordHash = new PasswordHasher(); var password = passwordHash.HashPassword(model.Password); var entity = Mapper.Map <AspNetUserModel, AspNetUser>(model); entity.PasswordHash = password; entity.SecurityStamp = Guid.NewGuid().ToString(); entity.Id = Guid.NewGuid().ToString(); _repository.Insert(entity); /*var repository = _repository.GetRepository<IdentityUserRole>(); * var reposRole = _repository.GetRepository<AspNetRole>(); * repository.Insert(new IdentityUserRole() * { * UserId = entity.Id, * RoleId = reposRole.Find(c=> c.Name == model.RoleName).Id * });*/ id = entity.Id; _unitOfWork.Commit(); } catch (Exception ex) { _unitOfWork.Rollback(); throw new Exception(ex.Message); } }
public async Task <IHttpActionResult> Post(EStatusLogViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var stf = await _eStatusLogService.InsertAsync(model, GetCurrentUserID()); _unitOfWorkAsync.Commit(); var resultObject = new EStatusLogViewModel() { Status = stf.Status, Note = stf.Note, ID = stf.Id, CreatDate = stf.CreatDate }; return(Created(resultObject)); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> Post(UserViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var user = await _userService.InsertUserAsync(model); _unitOfWorkAsync.Commit(); var returnUser = new UserViewModel() { Id = user.Id, PhoneNumber = user.PhoneNumber, Email = user.Email, IsBanned = user.IsBanned }; return(Created("Created new user", returnUser)); } catch (Exception ex) { throw; } }
public async Task <IHttpActionResult> Post(ReminderNoteViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { //ApplicationUser test = GetCurrentUser(); //model.UserAccount = test; var stf = await _reminderNoteService.InsertAsync(model, GetCurrentUserID()); _unitOfWorkAsync.Commit(); var resultObject = new ReminderNoteViewModel() { Note = stf.Note, ReminderDate = stf.ReminderDate, ID = stf.Id, Serial = stf.Serial }; return(Created(resultObject)); } catch (Exception ex) { throw ex; } }
public void Create(ComplaintModel model, string username) { try { _unitOfWork.BeginTransaction(); var complaint = new Complaint { Id = Guid.NewGuid().ToString(), Category = (int)model.Category, Description = model.Description, Summary = model.Summary, DateCreated = DateTime.UtcNow, Status = (int)ComplaintStatus.Created, Type = (int)model.Type, ComplainBy = model.ComplainBy }; _repository.Insert(complaint); _unitOfWork.Commit(); } catch (Exception e) { _unitOfWork.Rollback(); throw e; } }
/// <summary> /// Update an item /// </summary> /// <param name="id">Item id</param> /// <param name="model">Item model</param> /// <returns></returns> public virtual async Task <IHttpActionResult> Put(long id, T model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != model.Id) { return(BadRequest()); } try { _unitOfWork.BeginTransaction(); _service.Insert(model); await _unitOfWork.SaveChangesAsync(); _unitOfWork.Commit(); } catch (DbUpdateConcurrencyException) { if (!ModelExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> Post(StaffViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var stf = await _staffService.InsertAsync(model, GetCurrentUserID()); _unitOfWorkAsync.Commit(); var resultObject = new StaffViewModel() { FullName = stf.FullName, Email = stf.Email, ID = stf.Id, }; return(Created(resultObject)); } catch (Exception ex) { throw ex; } }
public async Task <IHttpActionResult> Post(InteractionHistoryViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var stf = await _interactionHistoryService.InsertAsync(model, GetCurrentUserID()); _unitOfWorkAsync.Commit(); var resultObject = new InteractionHistoryViewModel() { Type = stf.Type, Note = stf.Note, EventCode = stf.Event.Code, CreatDate = stf.CreatDate, ID = stf.Id, }; return(Created(resultObject)); } catch (Exception ex) { throw ex; } }
public async Task <IHttpActionResult> Post(EventViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var stf = await _eventService.InsertAsync(model, GetCurrentUserID()); var resultObject = new EventViewModel() { Code = stf.Code, Status = stf.Status, CustomerID = stf.Customer.Id, CustomerName = stf.Customer.Name, Note = stf.Note, ID = stf.Id, EventTypeID = stf.EventTypeId, EventPurposeID = stf.EventPurposeId, Birthday = stf.Customer.Birthday }; _unitOfWorkAsync.Commit(); return(Created(resultObject)); } catch (Exception ex) { throw new Exception(ex.ToString()); } }
public async Task <IHttpActionResult> Post(DetailEventViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var stf = await _detailEventService.InsertAsync(model, GetCurrentUserID()); _unitOfWorkAsync.Commit(); var resultObject = new DetailEventViewModel() { Serial = stf.Serial, EventCode = stf.Event.Code, Note = stf.Note, ID = stf.Id, DateSold = stf.DateSold, AgencySold = stf.AgencySold, AssociateName = stf.AssociateName }; return(Created(resultObject)); } catch (Exception ex) { throw ex; } }
public async Task <IHttpActionResult> Post(OrderViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var stf = await _orderService.InsertAsync(model, GetCurrentUserID()); _unitOfWorkAsync.Commit(); var resultObject = new OrderViewModel() { ID = stf.Id, Code = stf.Code, Total = stf.Total, IsGift = stf.IsGift, Note = stf.Note, CreatDate = DateTime.Now, LastModifiedDate = DateTime.Now }; return(Created(resultObject)); } catch (Exception ex) { throw ex; } }
public int Delete(int id) { try { _unitOfWork.BeginTransaction(); List <int> refItemIds = _repository.Query().Include(c => c.ReferenceItems).SelectQueryable().Where(c => c.Id == id).FirstOrDefault().ReferenceItems.Select(c => c.Id).ToList(); List <int> NotIds = _notificationBLL.Query().Include(c => c.Decision).SelectQueryable().Where(c => c.DecisionId == id).Select(c => c.Id).ToList(); refItemIds.ForEach(c => _referenceItemRepository.Delete(c)); _unitOfWork.SaveChanges(); NotIds.ForEach(c => _notificationBLL.Delete(c)); _repository.Delete(id); _unitOfWork.SaveChanges(); _unitOfWork.Commit(); } catch (Exception ex) { _unitOfWork.Rollback(); if (ex is DbUpdateException) { if (!(ex as DbUpdateException).InnerException.InnerException.Message.Contains("The DELETE statement conflicted with the REFERENCE constraint")) { ex = new Exception("Reference Item"); } } throw ex; } return(0); }
public async Task <IHttpActionResult> Post(CustomerViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var stf = await _customerService.InsertAsync(model, GetCurrentUserID()); _unitOfWorkAsync.Commit(); var resultObject = new CustomerViewModel() { ID = stf.Id, Name = stf.Name, PhoneNumber = stf.PhoneNumber, Birthday = stf.Birthday, Address = stf.Address, Ward = stf.Ward, District = stf.District, City = stf.City, Note = stf.Note, CreatDate = DateTime.Now, LastModifiedDate = DateTime.Now }; return(Created(resultObject)); } catch (Exception ex) { throw ex; } }
public async Task <IHttpActionResult> Post(OrderStatisticViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var stf = await _orderStatisticService.InsertAsync(model, GetCurrentUserID()); _unitOfWorkAsync.Commit(); var resultObject = new OrderStatisticViewModel() { ID = stf.Id, OrderDetailId = stf.OrderDetailId, OrderId = stf.OrderId, ProductAttributeId = stf.ProductAttributeId, ProductAttributeName = stf.ProductAttributeName, ProductAttributeNote = stf.ProductAttributeNote, Serial = stf.Serial, CreatDate = DateTime.Now, LastModifiedDate = DateTime.Now }; return(Created(resultObject)); } catch (Exception ex) { throw ex; } }
public async Task <IHttpActionResult> Post(ProductTypeViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var stf = await _productTypeService.InsertAsync(model, GetCurrentUserID()); var resultObject = new ProductTypeViewModel() { Name = stf.Name, Code = stf.Code, ID = stf.Id, }; bool de = _unitOfWorkAsync.Commit(); return(Created(resultObject)); } catch (Exception ex) { throw ex; } }
public void Create(UserProfileModel model) { try { _unitOfWork.BeginTransaction(); if (!String.IsNullOrEmpty(model.EmailAddress)) { if (_repository.EmailExists(model)) { throw new DuplicateNameException("A user with that e-mail address already exists!"); } } var entity = Mapper.Map <UserProfileModel, UserProfile>(model); entity.DateCreated = DateTime.Now; _repository.Insert(entity); model.Id = entity.Id; _unitOfWork.Commit(); } catch (DuplicateNameException ec) { throw new Exception("An error has occured " + ec.Message); } catch (Exception ec) { _unitOfWork.Rollback(); throw new Exception("An error has occured " + ec.Message); } }
public void Delete(int id) { try { //TODO:Throw clear exception once delete object has childs _unitOfWorkAsync.BeginTransaction(); _repository.Delete(id); _unitOfWorkAsync.SaveChanges(); _unitOfWorkAsync.Commit(); } catch { _unitOfWorkAsync.Rollback(); throw; } }
public int Delete(int id) { try { _unitOfWork.BeginTransaction(); _repository.Delete(id); _unitOfWork.SaveChanges(); _unitOfWork.Commit(); } catch (Exception ex) { _unitOfWork.Rollback(); throw ex; } return(0); }
public void Commit() { if (_uow != null) { _uow.Commit(); } }
public async Task <IHttpActionResult> Post(DistrictViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var stf = await _districtService.InsertAsync(model); _unitOfWorkAsync.Commit(); var resultObject = new DistrictViewModel() { name = model.name, slug = model.slug, type = model.type, name_with_type = model.name_with_type, code = model.code, }; return(Created(resultObject)); } catch (Exception ex) { throw ex; } }
public string ReserveTicket(string eventId, int tktQty) { _unitOfWorkAsync.BeginTransaction(); EventModel Event = _eventService.FindBy(eventId); if (!Event.CanReserveTicket(tktQty)) { _unitOfWorkAsync.Rollback(); return(String.Format("There are {0} ticket(s) available.", Event.AvailableAllocation())); } Event.ReserveTicket(tktQty); _eventService.Save(Event); _unitOfWorkAsync.Commit(); return(String.Format("{0} ticket(s) has been reserved for you for the event with Id {1}.", tktQty, Event.Id));; }
public void Create(UserModel model) { try { _unitOfWork.BeginTransaction(); var entity = Mapper.Map <UserModel, User>(model); entity.CreatedAt = DateTime.Now; _repository.Insert(entity); _unitOfWork.Commit(); } catch (Exception ex) { _unitOfWork.Rollback(); throw new Exception(ex.Message); } }
/// <summary> /// Overriding base implementation /// </summary> /// <param name="model"></param> /// <returns></returns> public override async Task <IHttpActionResult> Post(Role model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { _unitOfWork.BeginTransaction(); var modelToUpdate = await _service.FindAsync(model.Id); modelToUpdate.CopyFrom(model); _service.Update(modelToUpdate); await _unitOfWork.SaveChangesAsync(); _unitOfWork.Commit(); } catch (System.Exception ex) { return(InternalServerError(ex)); } return(CreatedAtRoute("DefaultApi", new { id = model.Id }, model)); }
public void Create(CourseModel model, int currentUserId) { try { _unitOfWork.BeginTransaction(); var entity = Mapper.Map <CourseModel, Course>(model); entity.CreatedAt = DateTime.Now; _levelRepository.Insert(entity); _unitOfWork.Commit(); } catch (Exception ex) { _unitOfWork.Rollback(); throw new Exception(ex.Message); } }
public async Task <IActionResult> Post(ParticipantViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var participant = await _participantService.InsertAsync(model); _unitOfWorkAsync.Commit(); return(Created("Created new participant", participant)); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> Post(QuestionViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var question = await _questionService.InsertAsync(model); _unitOfWorkAsync.Commit(); return(Created("Created new question", question)); } catch (Exception ex) { throw ex; } }
public void Create(SectionModel model, int currentUserId) { try { _unitOfWork.BeginTransaction(); if (model.IsActive) { UpdateActiveSession(); } var entity = Mapper.Map <SectionModel, Section>(model); entity.CreatedAt = DateTime.Now; _sectionRepository.Insert(entity); _unitOfWork.Commit(); } catch (Exception ex) { _unitOfWork.Rollback(); throw new Exception(ex.Message); } }
public async Task <IHttpActionResult> Post(EventPurposeViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var stf = await _eventPurposeService.InsertAsync(model, GetCurrentUserID()); _unitOfWorkAsync.Commit(); var resultObject = new EventPurposeViewModel() { ID = stf.Id, Name = stf.Name, }; return(Created(resultObject)); } catch (Exception ex) { throw ex; } }
public async Task <IHttpActionResult> Post(TopicPSViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var stf = await _topicPSService.InsertAsync(model); var resultObject = new TopicPSViewModel() { ID = stf.Id, BlogPSID = stf.BlogPS.Id, Title = stf.Title }; _unitOfWorkAsync.Commit(); return(Created(resultObject)); } catch (Exception ex) { throw new Exception(ex.ToString()); } }
public void Update(SubCategoryDTO dtoObject) { try { _unitOfWorkAsync.BeginTransaction(); SubCategory subCategory = new SubCategory(); Mapper.Map <SubCategoryDTO, SubCategory>(dtoObject, subCategory); Update(subCategory); _unitOfWorkAsync.SaveChanges(); _unitOfWorkAsync.Commit(); } catch (Exception ex) { _unitOfWorkAsync.Rollback(); throw ex; } }