public static void FillDto(Models.Order entity, ViewModels.OrderDto order) { order.Id = entity.Id; order.DateG = entity.DateG; order.Date = entity.Date; order.Mobile = entity.Mobile; order.Name = entity.Name; order.Remark = entity.Remark; order.Tax = entity.Tax; order.Discount = entity.Discount; order.Transport = entity.Transport; order.StatusId = entity.StatusId; order.PersonId = entity.PersonId; order.AuthId = entity.UserId; }
public static void Fill(Models.Order entity, ViewModels.OrderDto order) { entity.Id = order.Id; entity.DateG = order.DateG; entity.Date = order.Date; entity.Mobile = order.Mobile; entity.Name = order.Name; entity.Remark = order.Remark; entity.Tax = order.Tax; entity.Discount = order.Discount; entity.Transport = order.Transport; entity.StatusId = order.StatusId; entity.PersonId = order.PersonId; entity.UserId = order.AuthId; }
public async Task <IHttpActionResult> PostOrder(ViewModels.OrderDto dto) { if (dto == null) { return(Exceptions.getNullException(ModelState)); } if (!ModelState.IsValid) { return(Exceptions.getModelValidationException(ModelState)); } Order entity = null; if (dto.Id == -1) { entity = new Order(); unitOfWork.OrderRepository.Insert(entity); } else { entity = await unitOfWork.OrderRepository.GetByID(dto.Id); } if (entity == null) { return(Exceptions.getNotFoundException()); } ViewModels.OrderDto.Fill(entity, dto); entity.DateG = DateTime.Now; entity.Date = Convert.ToDecimal(Utils.DateTimeUtil.GetPersianDateTimeDigital((DateTime)entity.DateG)); //Person person = await unitOfWork.PersonRepository.GetViewPersonByMobile(dto.Mobile); //if (person == null) //{ // person = new Person() // { // Mobile = dto.Mobile, // FirstName = dto.Name, // DateCreate = DateTime.Now, // IsActive = true, // IsDeleted = false, // }; // unitOfWork.PersonRepository.Insert(person); //} //entity.Person = person; if (dto.Id != -1) { await unitOfWork.OrderRepository.RemoveOrderItems(dto.Id); } foreach (var x in dto.OrderItems) { var item = new OrderItem(); ViewModels.OrderItemDto.Fill(item, x); unitOfWork.OrderRepository.Insert(item); } var saveResult = await unitOfWork.SaveAsync(); if (saveResult.Code != HttpStatusCode.OK) { return(saveResult); } if (dto.SMS == 1) { sendOrderNoX(dto.Mobile, entity.Id.ToString(), dto.Name); } return(Ok(entity)); }