public async Task <HttpResponseMessage> Delete([FromBody] List <Contact> contacts) { ContactRule contactRule = new ContactRule(); foreach (var contact in contacts) { var item = contactRule.Find(contact.ID); if (item != null) { contactRule.Delete(item); await this.BusinessRule.SaveChangesAsync(); } } return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = (int)ZhivarEnums.ResultCode.Successful, data = contacts })); }
public async Task <HttpResponseMessage> LoadInvoiceTransObj([FromBody] int id) { try { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); var invoice = await Rule.FindAsync(id); InvoiceTransObj invoiceTransObj = new InvoiceTransObj(); invoiceTransObj.invoice = Mapper.Map <InvoiceVM>(invoice); invoiceTransObj.invoiceItems = invoiceTransObj.invoice.InvoiceItems; //invoiceTransObj.payments = await transactionRule.GetAllByInvoiceIdAsync(id,true,false); PayRecevieRule payRecevieRule = new PayRecevieRule(); invoiceTransObj.tempPayments = await payRecevieRule.GetTempPaymentsByInvoiceIdAsync(id); for (int i = 0; i < invoiceTransObj.invoiceItems.Count; i++) { ItemRule itemRule = new ItemRule(); invoiceTransObj.invoiceItems[i].Item = Mapper.Map <ItemVM>(await itemRule.FindAsync(invoiceTransObj.invoiceItems[i].ItemId)); } ContactRule contactRule = new ContactRule(); invoiceTransObj.invoice.Contact = Mapper.Map <ContactVM>(await contactRule.FindAsync(invoice.ContactId)); CashRule cashRule = new CashRule(); var cashes = await cashRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); invoiceTransObj.cashes = Mapper.Map <List <CashVM> >(cashes); BankRule bankRule = new BankRule(); var banks = await bankRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); invoiceTransObj.banks = Mapper.Map <List <BankVM> >(banks); return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.Successful, data = invoiceTransObj })); } catch (Exception ex) { throw; } }
public async Task <HttpResponseMessage> LoadCostTransObj([FromBody] int id) { try { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); var cost = await Rule.FindAsync(id); CostTransObj costTransObj = new CostTransObj(); costTransObj.cost = Mapper.Map <CostVM>(cost); costTransObj.costItems = costTransObj.cost.CostItems; TransactionRule transactionRule = new TransactionRule(); costTransObj.payments = await transactionRule.GetAllByCostIdAsync(id); for (int i = 0; i < costTransObj.costItems.Count; i++) { costTransObj.costItems[i].Item = await this.BusinessRule.UnitOfWork.RepositoryAsync <DomainClasses.Accounting.Account>().FindAsync(costTransObj.costItems[i].ItemId); } ContactRule contactRule = new ContactRule(); costTransObj.cost.Contact = Mapper.Map <ContactVM>(await contactRule.FindAsync(cost.ContactId)); CashRule cashRule = new CashRule(); var cashes = await cashRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); costTransObj.cashes = Mapper.Map <List <CashVM> >(cashes); BankRule bankRule = new BankRule(); var banks = await bankRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); costTransObj.banks = Mapper.Map <List <BankVM> >(banks); return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.Successful, data = costTransObj })); } catch (Exception ex) { throw; } }
public async Task <HttpResponseMessage> loadCostData([FromBody] int id) { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); var resualt = new CostData(); List <ContactVM> contacts = new List <ContactVM>(); ContactRule contactRule = new ContactRule(); var contactsSource = await contactRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); contactsSource = contactsSource.ToList(); contacts = Mapper.Map <IList <Contact>, List <ContactVM> >(contactsSource); foreach (var contact in contacts) { contact.DetailAccount = new DetailAccount() { Code = contact.Code, Id = (int)contact.ID, Node = new Node() { FamilyTree = "اشخاص", Id = (int)contact.ID, Name = "اشخاص" } }; //var account1104 = await CalcAccountByCodeTafziliAsync(organId, "1104" + contact.Code); //var account1105 = await CalcAccountByCodeTafziliAsync(organId, "1105" + contact.Code); //var account2101 = await CalcAccountByCodeTafziliAsync(organId, "2101" + contact.Code); //contact.Balance = account1104.sumTotal + account1105.sumTotal + account2101.sumTotal; //contact.Credits = account1104.sumCredit + account1105.sumCredit + account2101.sumCredit; //contact.Liability = account1104.sumDebit + account1105.sumDebit + account2101.sumDebit; } resualt.contacts = contacts; resualt.costSettings = new InvoiceSettings() { allowApproveWithoutStock = false, autoAddTax = true, bottomMargin = "20", businessLogo = "", font = "Iransans", fontSize = "Medium", footerNote = "", footerNoteDraft = "", hideZeroItems = false, onlineInvoiceEnabled = false, pageSize = "A4portrait", payReceiptTitle = "رسید پرداخت وجه / چک", purchaseInvoiceTitle = "فاکتور خرید", receiveReceiptTitle = "رسید دریافت وجه / چک", rowPerPage = "18", saleDraftInvoiceTitle = "پیش فاکتور", saleInvoiceTitle = "صورتحساب فروش کالا و خدمات", showAmountInWords = false, showCustomerBalance = false, showItemUnit = false, showSignaturePlace = true, showTransactions = true, showVendorInfo = true, topMargin = "10", updateBuyPrice = false, updateSellPrice = false }; AccountRule accountRule = new AccountRule(); List <DomainClasses.Accounting.Account> accounts = await accountRule.GetAllByOrganIdAsync(organId); var parentAccount = accounts.Where(x => x.ComplteCoding == "8205").SingleOrDefault(); accounts = accounts.Where(x => x.ParentId == parentAccount.ID).ToList(); resualt.items = accounts; var CostItems = new List <CostItemVM>(); if (id == 0) { CostItems.Add(new CostItemVM() { Description = "", ID = 0, RowNumber = 0, Sum = 0, Rest = 0 }); CostItems.Add(new CostItemVM() { Description = "", ID = 0, RowNumber = 1, Sum = 0, Rest = 0 }); CostItems.Add(new CostItemVM() { Description = "", ID = 0, RowNumber = 2, Sum = 0, Rest = 0 }); CostItems.Add(new CostItemVM() { Description = "", ID = 0, RowNumber = 3, Sum = 0, Rest = 0 }); resualt.cost = new CostVM() { Contact = null, ContactTitle = "", DateTime = DateTime.Now, DisplayDate = PersianDateUtils.ToPersianDate(DateTime.Now), ID = 0, CostItems = CostItems, Number = await createNumberCost(organId), Paid = 0, Payable = 0, Rest = 0, Status = 0, Sum = 0, Explain = "" }; } else { CostRule costRule = new CostRule(); var cost = await costRule.FindAsync(id); foreach (var costItem in cost.CostItems ?? new List <CostItem>()) { CostItems.Add(new CostItemVM() { Description = costItem.Description, ID = costItem.ID, RowNumber = costItem.RowNumber, Sum = costItem.Sum, Rest = costItem.Rest, Item = accounts.Where(x => x.ID == costItem.ItemId).SingleOrDefault(), ItemId = costItem.ItemId }); } var contact = new Contact(); if (cost.ContactId > 0) { contact = await this.Rule.UnitOfWork.RepositoryAsync <Contact>().Queryable().Where(x => x.ID == cost.ContactId).SingleOrDefaultAsync2(); } resualt.cost = new CostVM() { Contact = Mapper.Map <Contact, ContactVM>(contact), ContactTitle = contact.Name, DateTime = cost.DateTime, DisplayDate = cost.DisplayDate, ID = cost.ID, CostItems = CostItems, Number = cost.Number, Paid = cost.Paid, Payable = cost.Payable, Rest = cost.Rest, Status = cost.Status, Sum = cost.Sum, Explain = cost.Explain }; return(Request.CreateResponse(HttpStatusCode.OK, new { resualtCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt })); } return(Request.CreateResponse(HttpStatusCode.OK, new { resualtCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt })); }
private async Task CreateShareHolderAccounts(int organId, int contactId) { ContactRule contactRule = new ContactRule(); var contact = await contactRule.FindAsync(contactId); AccountRule accountRule = new AccountRule(); var accounts = await accountRule.GetAllByOrganIdAsync(organId); var accountShareholder = accounts.Where(x => x.ComplteCoding == "3101").SingleOrDefault(); DomainClasses.Accounting.Account tempAccountShareholder = new DomainClasses.Accounting.Account(); tempAccountShareholder = accounts.Where(x => x.ComplteCoding == "3101" + contact.Code).SingleOrDefault(); if (tempAccountShareholder == null) { tempAccountShareholder = new DomainClasses.Accounting.Account(); tempAccountShareholder.Coding = contact.Code; tempAccountShareholder.ComplteCoding = "3101" + contact.Code; tempAccountShareholder.Level = ZhivarEnums.AccountType.Tafzeli; tempAccountShareholder.Name = contact.Name; tempAccountShareholder.OrganId = organId; tempAccountShareholder.ParentId = accountShareholder.ID; accountRule.Insert(tempAccountShareholder); } accountShareholder = accounts.Where(x => x.ComplteCoding == "3102").SingleOrDefault(); tempAccountShareholder = new DomainClasses.Accounting.Account(); tempAccountShareholder = accounts.Where(x => x.ComplteCoding == "3102" + contact.Code).SingleOrDefault(); if (tempAccountShareholder == null) { tempAccountShareholder = new DomainClasses.Accounting.Account(); tempAccountShareholder.Coding = contact.Code; tempAccountShareholder.ComplteCoding = "3102" + contact.Code; tempAccountShareholder.Level = ZhivarEnums.AccountType.Tafzeli; tempAccountShareholder.Name = contact.Name; tempAccountShareholder.OrganId = organId; tempAccountShareholder.ParentId = accountShareholder.ID; accountRule.Insert(tempAccountShareholder); } accountShareholder = accounts.Where(x => x.ComplteCoding == "3103").SingleOrDefault(); tempAccountShareholder = new DomainClasses.Accounting.Account(); tempAccountShareholder = accounts.Where(x => x.ComplteCoding == "3103" + contact.Code).SingleOrDefault(); if (tempAccountShareholder == null) { tempAccountShareholder = new DomainClasses.Accounting.Account(); tempAccountShareholder.Coding = contact.Code; tempAccountShareholder.ComplteCoding = "3103" + contact.Code; tempAccountShareholder.Level = ZhivarEnums.AccountType.Tafzeli; tempAccountShareholder.Name = contact.Name; tempAccountShareholder.OrganId = organId; tempAccountShareholder.ParentId = accountShareholder.ID; accountRule.Insert(tempAccountShareholder); } accountShareholder = accounts.Where(x => x.ComplteCoding == "3104").SingleOrDefault(); tempAccountShareholder = new DomainClasses.Accounting.Account(); tempAccountShareholder = accounts.Where(x => x.ComplteCoding == "3104" + contact.Code).SingleOrDefault(); if (tempAccountShareholder == null) { tempAccountShareholder = new DomainClasses.Accounting.Account(); tempAccountShareholder.Coding = contact.Code; tempAccountShareholder.ComplteCoding = "3104" + contact.Code; tempAccountShareholder.Level = ZhivarEnums.AccountType.Tafzeli; tempAccountShareholder.Name = contact.Name; tempAccountShareholder.OrganId = organId; tempAccountShareholder.ParentId = accountShareholder.ID; accountRule.Insert(tempAccountShareholder); } accountShareholder = accounts.Where(x => x.ComplteCoding == "3105").SingleOrDefault(); tempAccountShareholder = new DomainClasses.Accounting.Account(); tempAccountShareholder = accounts.Where(x => x.ComplteCoding == "3105" + contact.Code).SingleOrDefault(); if (tempAccountShareholder == null) { tempAccountShareholder = new DomainClasses.Accounting.Account(); tempAccountShareholder.Coding = contact.Code; tempAccountShareholder.ComplteCoding = "3105" + contact.Code; tempAccountShareholder.Level = ZhivarEnums.AccountType.Tafzeli; tempAccountShareholder.Name = contact.Name; tempAccountShareholder.OrganId = organId; tempAccountShareholder.ParentId = accountShareholder.ID; accountRule.Insert(tempAccountShareholder); } }
public async Task <HttpResponseMessage> loadInvoiceData([FromBody] int id) { try { } catch (Exception ex) { throw; } var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); var resualt = new InvoiceData(); List <ContactVM> contacts = new List <ContactVM>(); ContactRule contactRule = new ContactRule(); var contactsSource = await contactRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); contactsSource = contactsSource.ToList(); contacts = TranslateHelper.TranslateEntityToEntityVMListContact(contactsSource); foreach (var contact in contacts) { contact.DetailAccount = new DetailAccount() { Code = contact.Code, Id = (int)contact.ID, Node = new Node() { FamilyTree = "اشخاص", Id = (int)contact.ID, Name = "اشخاص" } }; //var account1104 = await CalcAccountByCodeTafziliAsync(organId, "1104" + contact.Code); //var account1105 = await CalcAccountByCodeTafziliAsync(organId, "1105" + contact.Code); //var account2101 = await CalcAccountByCodeTafziliAsync(organId, "2101" + contact.Code); //contact.Balance = account1104.sumTotal + account1105.sumTotal + account2101.sumTotal; //contact.Credits = account1104.sumCredit + account1105.sumCredit + account2101.sumCredit; //contact.Liability = account1104.sumDebit + account1105.sumDebit + account2101.sumDebit; } resualt.contacts = contacts; resualt.invoiceSettings = new InvoiceSettings() { allowApproveWithoutStock = false, autoAddTax = true, bottomMargin = "20", businessLogo = "", font = "Iransans", fontSize = "Medium", footerNote = "", footerNoteDraft = "", hideZeroItems = false, onlineInvoiceEnabled = false, pageSize = "A4portrait", payReceiptTitle = "رسید پرداخت وجه / چک", purchaseInvoiceTitle = "فاکتور خرید", receiveReceiptTitle = "رسید دریافت وجه / چک", rowPerPage = "18", saleDraftInvoiceTitle = "پیش فاکتور", saleInvoiceTitle = "صورتحساب فروش کالا و خدمات", showAmountInWords = false, showCustomerBalance = false, showItemUnit = false, showSignaturePlace = true, showTransactions = true, showVendorInfo = true, topMargin = "10", updateBuyPrice = false, updateSellPrice = false }; ItemGroupRule itemGroupRule = new ItemGroupRule(); var itemGroups = await itemGroupRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); var items = new List <ItemVM>(); var item = new ItemVM(); foreach (var itemGroup in itemGroups) { foreach (var KalaKhadmat in itemGroup.Items) { item = new ItemVM() { Barcode = "", BuyPrice = KalaKhadmat.BuyPrice, DetailAccount = new DetailAccount() { Code = KalaKhadmat.Code, Id = KalaKhadmat.ID, Node = new Node() { FamilyTree = itemGroup.Name, Name = itemGroup.Name, Id = itemGroup.ID } }, ID = KalaKhadmat.ID, Name = KalaKhadmat.Name, UnitID = KalaKhadmat.UnitID, SalesTitle = KalaKhadmat.SalesTitle, PurchasesTitle = KalaKhadmat.PurchasesTitle, SellPrice = KalaKhadmat.SellPrice, ItemType = KalaKhadmat.ItemType, Stock = KalaKhadmat.Stock, Code = KalaKhadmat.Code, IsGoods = KalaKhadmat.IsGoods, IsService = KalaKhadmat.IsService, MoneyStock = KalaKhadmat.MoneyStock, OrganId = KalaKhadmat.OrganId, ItemGroupId = KalaKhadmat.ItemGroupId }; items.Add(item); } } resualt.items = items; var InvoiceItems = new List <InvoiceItemVM>(); if (id == 0) { InvoiceItems.Add(new InvoiceItemVM() { Description = "", Discount = 0, ID = 0, Inv = null, Item = null, ItemInput = "", Quantity = 0, RowNumber = 0, Sum = 0, Tax = 0, TotalAmount = 0, Unit = 0, UnitPrice = 0 }); InvoiceItems.Add(new InvoiceItemVM() { Description = "", Discount = 0, ID = 0, Inv = null, Item = null, ItemInput = "", Quantity = 0, RowNumber = 1, Sum = 0, Tax = 0, TotalAmount = 0, Unit = 0, UnitPrice = 0 }); InvoiceItems.Add(new InvoiceItemVM() { Description = "", Discount = 0, ID = 0, Inv = null, Item = null, ItemInput = "", Quantity = 0, RowNumber = 2, Sum = 0, Tax = 0, TotalAmount = 0, Unit = 0, UnitPrice = 0 }); InvoiceItems.Add(new InvoiceItemVM() { Description = "", Discount = 0, ID = 0, Inv = null, Item = null, ItemInput = "", Quantity = 0, RowNumber = 3, Sum = 0, Tax = 0, TotalAmount = 0, Unit = 0, UnitPrice = 0 }); resualt.invoice = new InvoiceVM() { Contact = null, ContactTitle = "", DateTime = DateTime.Now, DisplayDate = PersianDateUtils.ToPersianDate(DateTime.Now), DisplayDueDate = PersianDateUtils.ToPersianDate(DateTime.Now), invoiceDueDate = PersianDateUtils.ToPersianDate(DateTime.Now), DueDate = DateTime.Now, ID = 0, InvoiceItems = InvoiceItems, InvoiceStatusString = "موقت", InvoiceType = 0, InvoiceTypeString = "فروش", IsDraft = true, IsPurchase = false, IsPurchaseReturn = false, IsSale = true, IsSaleReturn = false, IsWaste = false, Note = "", Number = await createNumberInvoice(organId), Paid = 0, Payable = 0, Profit = 0, Reference = "", Rest = 0, Returned = false, Sent = false, Status = 0, Sum = 0, Tag = "" }; } else { var invoice = await Rule.FindAsync(id); foreach (var invoiceItem in invoice.InvoiceItems ?? new List <InvoiceItem>()) { InvoiceItems.Add(new InvoiceItemVM() { Description = invoiceItem.Description, Discount = invoiceItem.Discount, ID = invoiceItem.ID, Inv = invoiceItem.Inv, Item = Mapper.Map <Item, ItemVM>(this.BusinessRule.UnitOfWork.Repository <Item>().Find(invoiceItem.ItemId)), ItemId = invoiceItem.ItemId, ItemInput = invoiceItem.ItemInput, Quantity = invoiceItem.Quantity, RowNumber = invoiceItem.RowNumber, Sum = invoiceItem.SumInvoiceItem, Tax = invoiceItem.Tax, TotalAmount = invoiceItem.TotalAmount, Unit = invoiceItem.UnitInvoiceItem, UnitPrice = invoiceItem.UnitPrice }); } resualt.invoice = new InvoiceVM() { Contact = Mapper.Map <Contact, ContactVM>(this.BusinessRule.UnitOfWork.Repository <Contact>().Find(invoice.ContactId)), ContactTitle = invoice.ContactTitle, DateTime = invoice.DateTime, DisplayDate = invoice.DisplayDate, DisplayDueDate = invoice.DisplayDueDate, invoiceDueDate = invoice.DisplayDueDate, DueDate = invoice.DueDate, ID = invoice.ID, InvoiceItems = InvoiceItems, InvoiceStatusString = invoice.InvoiceStatusString, InvoiceType = invoice.InvoiceType, InvoiceTypeString = invoice.InvoiceTypeString, IsDraft = invoice.IsDraft, IsPurchase = invoice.IsPurchase, IsPurchaseReturn = invoice.IsPurchaseReturn, IsSale = invoice.IsSale, IsSaleReturn = invoice.IsSaleReturn, IsWaste = false, Note = invoice.Note, Number = invoice.Number, Paid = invoice.Paid, Payable = invoice.Payable, Profit = invoice.Profit, Reference = invoice.Refrence, Rest = invoice.Rest, Returned = invoice.Returned, Sent = invoice.Sent, Status = invoice.Status, Sum = invoice.Sum, Tag = invoice.Tag }; return(Request.CreateResponse(HttpStatusCode.OK, new { resualtCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt })); } return(Request.CreateResponse(HttpStatusCode.OK, new { resualtCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt })); }
public async Task <HttpResponseMessage> SaveInvoice([FromBody] InvoiceVM invoiceVM) { try { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); FinanYearRule finanYearRule = new FinanYearRule(); var finanYears = await finanYearRule.GetAllByOrganIdAsync(organId); var finanYear = finanYears.Where(x => x.Closed == false && x.OrganId == organId); invoiceVM.InvoiceItems = invoiceVM.InvoiceItems.Where(x => x.Item != null).ToList(); foreach (var invoiceItem in invoiceVM.InvoiceItems) { if (invoiceItem.Item != null) { invoiceItem.ItemId = invoiceItem.Item.ID; } } if (invoiceVM.Contact != null) { invoiceVM.ContactId = invoiceVM.Contact.ID; } Invoice invoice = new Invoice(); Mapper.Map(invoiceVM, invoice); invoice.OrganId = organId; //if (invoice.Contact != null) //{ // invoice.ContactId = invoice.Contact.ID; //} // invoice.InvoiceItems = invoice.InvoiceItems.Where(x => x.ItemId != 0).ToList(); InvoiceValidate validator = new InvoiceValidate(); FluentValidation.Results.ValidationResult results = validator.Validate(invoice); string failurs = ""; if (!results.IsValid) { foreach (var error in results.Errors) { failurs += "<br/>" + error.ErrorMessage; } return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.ValidationError, data = failurs })); } if (invoice.ID > 0) { foreach (var invoiceItem in invoice.InvoiceItems) { invoiceItem.InvoiceId = invoice.ID; if (invoiceItem.ID > 0) { invoiceItem.ObjectState = OMF.Common.Enums.ObjectState.Modified; } else { invoiceItem.ObjectState = OMF.Common.Enums.ObjectState.Added; } //if (invoiceItem.Item != null) // invoiceItem.Item = null;//.ObjectState = OMF.Common.Enums.ObjectState.Unchanged; } invoice.ObjectState = OMF.Common.Enums.ObjectState.Modified; } else { foreach (var invoiceItem in invoice.InvoiceItems) { invoiceItem.ObjectState = OMF.Common.Enums.ObjectState.Added; //if (invoiceItem.Item != null) // invoiceItem.Item = null;//.ObjectState = OMF.Common.Enums.ObjectState.Unchanged; } invoice.ObjectState = OMF.Common.Enums.ObjectState.Added; } this.BusinessRule.UnitOfWork.RepositoryAsync <Invoice>().InsertOrUpdateGraph(invoice); ContactRule contactRule = new ContactRule(); await contactRule.UpdateContact(invoice.InvoiceType, invoice.ContactId); //await this.BusinessRule.UnitOfWork.SaveChangesAsync(); if (invoice.Status == ZhivarEnums.NoeInsertFactor.WaitingToReceive) { var document = await Rule.RegisterDocumentAsync(invoiceVM, organId); DocumentRule documentRule = new DocumentRule(); await documentRule.InsertAsync(document, organId); await documentRule.SaveChangesAsync(); invoice.DocumentID = document.ID; this.BusinessRule.UnitOfWork.RepositoryAsync <Invoice>().Update(invoice); //await this.BusinessRule.UnitOfWork.SaveChangesAsync(); } await this.BusinessRule.UnitOfWork.SaveChangesAsync(); // await RegisterDocument(invoice, organId); return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.Successful, data = invoice })); } catch (Exception ex) { throw; } }
public async Task <HttpResponseMessage> loadReservationData([FromBody] loadReservationDataBusi reservationData) { try { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); var resualt = new ReservationData(); List <ContactVM> contacts = new List <ContactVM>(); ContactRule contactRule = new ContactRule(); var contactsSource = await contactRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); contactsSource = contactsSource.ToList(); contacts = TranslateHelper.TranslateEntityToEntityVMListContact(contactsSource); foreach (var contact in contacts) { contact.DetailAccount = new DetailAccount() { Code = contact.Code, Id = (int)contact.ID, Node = new Node() { FamilyTree = "اشخاص", Id = (int)contact.ID, Name = "اشخاص" } }; } resualt.contacts = contacts; NoeEjareRule noeEjareRule = new NoeEjareRule(); var noeEjares = await noeEjareRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); resualt.noeEjares = noeEjares; GoroheSazeRule goroheSazeRule = new GoroheSazeRule(); var itemGroups = await goroheSazeRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); var items = new List <SazeVM>(); var item = new SazeVM(); foreach (var itemGroup in itemGroups) { foreach (var KalaKhadmat in itemGroup.Items) { item = new SazeVM() { DetailAccount = new DetailAccount() { Code = KalaKhadmat.Code, Id = KalaKhadmat.ID, Node = new Node() { FamilyTree = itemGroup.Title, Name = itemGroup.Title, Id = itemGroup.ID } }, Code = KalaKhadmat.Code, OrganId = KalaKhadmat.OrganId, Address = KalaKhadmat.Address, Arz = KalaKhadmat.Arz, GoroheSazeID = KalaKhadmat.GoroheSazeID, ID = KalaKhadmat.ID, Title = KalaKhadmat.Title, Tol = KalaKhadmat.Tol, NoeSazeId = KalaKhadmat.NoeSazeId, NoeEjare = KalaKhadmat.NoeEjare, GoroheName = KalaKhadmat.GoroheName, NoeEjareName = KalaKhadmat.NoeEjareName, NoeSazeName = KalaKhadmat.NoeSazeName, Latitude = KalaKhadmat.Latitude, Longitude = KalaKhadmat.Longitude, NoorDard = KalaKhadmat.NoorDard, NoeEjareID = KalaKhadmat.NoeEjareID, }; items.Add(item); } } resualt.items = items; var Reservation_DetailVMs = new List <Reservation_DetailVM>(); var reservation_DetailVM = new List <Reservation_DetailVM>(); if (reservationData.id == 0) { var countRes = 0; if (reservationData.lstSaze != null && reservationData.lstSaze.Count > 0) { reservationData.lstSaze = reservationData.lstSaze.Where(x => x.sazeID != 0).ToList(); foreach (var lstSaze in reservationData.lstSaze) { var saze = Mapper.Map <Saze, SazeVM>(this.BusinessRule.UnitOfWork.Repository <Saze>().Find(lstSaze.sazeID)); var startDate = DateTime.Now; var displayStartDate = PersianDateUtils.ToPersianDateTime(DateTime.Now); bool minValue = false; bool maxValue = false; if (!string.IsNullOrEmpty(lstSaze.minDate) && !string.IsNullOrWhiteSpace(lstSaze.minDate)) { startDate = PersianDateUtils.ToDateTime(lstSaze.minDate); displayStartDate = lstSaze.minDate; minValue = true; } var endDate = DateTime.Now; var displayEndDate = PersianDateUtils.ToPersianDateTime(DateTime.Now); if (!string.IsNullOrEmpty(lstSaze.maxDate) && !string.IsNullOrWhiteSpace(lstSaze.maxDate)) { endDate = PersianDateUtils.ToDateTime(lstSaze.maxDate); displayStartDate = lstSaze.maxDate; maxValue = true; } var quantity = 0; if (minValue && maxValue) { var diff = endDate - startDate; var days = diff.TotalDays; quantity = Convert.ToInt32(days); } Reservation_DetailVMs.Add(new Reservation_DetailVM() { ID = 0, Quantity = quantity, Saze = saze, SazeID = saze.ID, NoeEjare = Mapper.Map <NoeEjare, NoeEjareVM>(this.BusinessRule.UnitOfWork.Repository <NoeEjare>().Find(saze.NoeEjareID)), NoeEjareID = saze.NoeEjareID, RowNumber = 0, StartDate = startDate, StartDisplayDate = displayStartDate, //EndDate = endDate, //EndDisplayDate = lstSaze.maxDate, }); countRes += 1; } if (countRes < 3) { for (int i = 0; i < 3 - countRes; i++) { Reservation_DetailVMs.Add(new Reservation_DetailVM() { ID = 0, Quantity = 0, Saze = null, SazeID = 0, NoeEjare = null, NoeEjareID = 0, RowNumber = countRes + i, //StartDate = startDate, StartDisplayDate = "", //EndDate = endDate, //EndDisplayDate = lstSaze.maxDate, }); } } } else { Reservation_DetailVMs.Add(new Reservation_DetailVM() { ID = 0, Quantity = 0, RowNumber = 0 }); Reservation_DetailVMs.Add(new Reservation_DetailVM() { ID = 0, Quantity = 0, RowNumber = 1 }); Reservation_DetailVMs.Add(new Reservation_DetailVM() { ID = 0, Quantity = 0, RowNumber = 2 }); Reservation_DetailVMs.Add(new Reservation_DetailVM() { ID = 0, Quantity = 0, RowNumber = 3 }); } resualt.Reservation = new ReservationVM() { //Contact = Mapper.Map<Contact, ContactVM>(this.BusinessRule.UnitOfWork.Repository<Contact>().Find(reservation.ContactID)), ID = 0, DisplayRegisterDate = Utilities.PersianDateUtils.ToPersianDateTime(DateTime.Now), // ContactID = reservation.ContactID, OrganID = organId, RegisterDate = DateTime.Now, ReservationDetails = Reservation_DetailVMs }; return(Request.CreateResponse(HttpStatusCode.OK, new { resualtCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt })); } else { var reservation = await Rule.FindAsync(reservationData.id); foreach (var reservationDetail in reservation.ReservationDetails ?? new List <Reservation_Detail>()) { Reservation_DetailVMs.Add(new Reservation_DetailVM() { ID = reservationDetail.ID, Saze = Mapper.Map <Saze, SazeVM>(this.BusinessRule.UnitOfWork.Repository <Saze>().Find(reservationDetail.SazeID)), SazeID = reservationDetail.SazeID, Quantity = reservationDetail.Quantity, NoeEjare = Mapper.Map <NoeEjare, NoeEjareVM>(this.BusinessRule.UnitOfWork.Repository <NoeEjare>().Find(reservationDetail.NoeEjareID)), NoeEjareID = reservationDetail.NoeEjareID, EndDate = reservationDetail.EndDate, EndDisplayDate = reservationDetail.EndDisplayDate, ReservationID = reservationDetail.ReservationID, StartDate = reservationDetail.StartDate, StartDisplayDate = reservationDetail.StartDisplayDate, UnitPrice = reservationDetail.UnitPrice, PriceBazareab = reservationDetail.PriceBazareab, PriceTarah = reservationDetail.PriceTarah, PriceChap = reservationDetail.PriceChap, PriceNasab = reservationDetail.PriceNasab, RowNumber = reservationDetail.RowNumber }); } resualt.Reservation = new ReservationVM() { Contact = Mapper.Map <Contact, ContactVM>(this.BusinessRule.UnitOfWork.Repository <Contact>().Find(reservation.ContactID)), ID = reservation.ID, DisplayRegisterDate = reservation.DisplayRegisterDate, ContactID = reservation.ContactID, OrganID = reservation.OrganID, RegisterDate = reservation.RegisterDate, ValiditDuration = reservation.ValiditDuration, ReservationDetails = Reservation_DetailVMs }; return(Request.CreateResponse(HttpStatusCode.OK, new { resualtCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt })); } } catch (Exception ex) { throw; } }