public NewComplaintReportViewModel(ComplaintReport c) { //MachineNo1 = c.MachineNo1; //MachineNo2 = c.MachineNo2; //DealerId = c.DealerId; //SaleDate = c.SaleDate; //DamageDate = c.DamageDate; //RepairDate = c.RepairDate; //TimeAmount = c.TimeAmount; //EngineNo = c.EngineNo; //CustomerId = c.Customer.CustomerId; //ProductModel = c.ProductModel.ProductModelId; //Status = (int)c.Status; //Closed = c.Closed; //Error = c.Error; //ReasonForError = c.ReasonForError; //PartsMarked = c.PartsMarked; //PartsReturned = c.PartsReturned; //CreateEmail = c.CreateEmail; }
public HttpResponseMessage NewComplaintReport(NewComplaintReportViewModel model) { if (!ModelState.IsValid) { var validationErrors = ModelState.Values.Where(E => E.Errors.Count > 0) .SelectMany(E => E.Errors) .Where(E => !E.ErrorMessage.IsNullOrWhiteSpace()).Select(c => c.ErrorMessage) .ToList(); return(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent(string.Join(",", validationErrors.Select(e => e))) }); } //Get ProductModel //var productModels = ctx.ProductModels.Where(pm => model.ProductModels.Contains(pm.ProductModelId)).ToList(); // Customer var newCustomer = new Customer() { Name = model.Customer.Name, Address = model.Customer.Address, CustomerType = model.Customer.CustomerType }; var newCreatedCustomer = ctx.Customers.Add(newCustomer); ctx.SaveChanges(); // Report var newReport = new ComplaintReport() { MachineNo1 = model.MachineNo1, MachineNo2 = model.MachineNo2, //Forhandler/Member MemberId = memberRepo.GetCurrentMemberId(), //Kunde CustomerId = newCreatedCustomer.CustomerId, ProductModelId = (int)model.ProductModel, EngineNo = model.EngineNo, TimeAmount = (int)model.TimeAmount, SaleDate = (DateTime)model.SaleDate, DamageDate = (DateTime)model.DamageDate, RepairDate = (DateTime)model.RepairDate, Error = model.Error, ReasonForError = model.ReasonForError, PartsMarked = model.PartsMarked, PartsReturned = model.PartsReturned, CreateEmail = model.CreateEmail, Status = Status.Draft, //Closed = model.Closed, CreatedByDealerDate = DateTime.Now, LastEditedByDealerId = memberRepo.GetCurrentMemberId(), }; //var id = model.Parts.First().PartId; //var reportPart = new ComplaintReportPart //{ // ComplaintReport = newReport, // Part = ctx.Parts.SingleOrDefault(p => p.PartId == id), // Amount = model.Parts.First().Amount //}; var partsToAdd = model.Parts.Select(p => new ComplaintReportPart { ComplaintReport = newReport, Part = ctx.Parts.SingleOrDefault(pa => pa.PartId == p.PartId), Amount = p.Amount }); ctx.ComplaintReportParts.AddRange(partsToAdd); //ctx.SaveChanges(); //var selectedDealer = ctx.Dealers.SingleOrDefault(d => d.DealerId == Int32.Parse(model.DealerName)); //newReport.Dealer = selectedDealer; //newReport.Dealer = selectedDealer; var re = ctx.ComplaintReports.Add(newReport); ctx.SaveChanges(); var newCreatedReport = ctx.ComplaintReports.Include(a => a.Customer).Include(a => a.ProductModel).SingleOrDefault(d => d.ComplaintReportId == re.ComplaintReportId); //return new Domain.Models.NewComplaintReportViewModel(re); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(newCreatedReport.ComplaintReportId.ToString()) }); }
public ExistingComplaintReportViewModel(ComplaintReport c) { ComplaintReportId = c.ComplaintReportId; MachineNo1 = c.MachineNo1; MachineNo2 = c.MachineNo2; DealerId = c.MemberId; SaleDate = c.SaleDate; DamageDate = c.DamageDate; RepairDate = c.RepairDate; TimeAmount = c.TimeAmount; EngineNo = c.EngineNo; Customer = new CustomerViewModel() { CustomerId = c.Customer.CustomerId, Name = c.Customer.Name, Address = c.Customer.Address, CustomerType = c.Customer.CustomerType }; var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(Umbraco.Web.UmbracoContext.Current); var memberId = memberShipHelper.GetCurrentMemberId(); var memberService = ApplicationContext.Current.Services.MemberService; var m = memberService.GetById(c.MemberId); Dealer = new DealerViewModel(m); Product = new ProductViewModel(c.ProductModel.Product); ProductModel = new ProductModelViewModel(c.ProductModel); Status = c.Status; SelectedProduct = c.ProductModel.ProductId; SelectedProductModel = c.ProductModelId; Closed = c.Closed; Error = c.Error; ReasonForError = c.ReasonForError; PartsMarked = c.PartsMarked; PartsReturned = c.PartsReturned; CreateEmail = c.CreateEmail; //Parts = new List<PartViewModel>(); //Parts.AddRange(c.ComplaintReportParts.Select(p => // new PartViewModel(){ // PartId = p.PartId, // Description = p.Description, // PartNo = p.PartNo, // Price = p.Price, // Shipping = p.Shipping, // })); var parts = c.ComplaintReportParts.Select(p => new PartViewModel() { PartId = p.PartId, Description = p.Part.Description, PartNo = p.Part.PartNo, Price = p.Part.Price, Shipping = p.Part.Shipping, Amount = p.Amount }); Parts = new List <PartViewModel>(); Parts.AddRange(parts); SentToApproval = c.SentToApproval; }
public EditComplaintReportViewModel(ComplaintReport c) { }