public ResponseDto UpdateProducts(FicheDto ficheDto) { ResponseDto responseDto = new ResponseDto(); if (ficheDto == null || ficheDto.ProductList == null || ficheDto.ProductList.Count == 0) { responseDto.IsSuccess = false; responseDto.Message = Business.Stc.GetDicValue("xNoProduct", Session.RealPerson.LanguageId); return(responseDto); } FicheBo ficheBo = new FicheBo() { DebtPersonId = ficheDto.DebtPersonId, CreditPersonId = ficheDto.CreditPersonId, CurrencyId = ficheDto.CurrencyId, // We do not need other fields. Session = Session }; ficheBo.ProductList = (from x in ficheDto.ProductList //where !x.IsDeleted select new FicheProductBo { Id = x.Id, ProductId = x.ProductId, Quantity = x.Quantity, UnitPrice = x.UnitPrice, DiscountRate = x.DiscountRate, DiscountTotal = x.DiscountTotal, VatRate = x.VatRate, Notes = x.Notes, IsDeleted = x.IsDeleted }).ToList(); ResponseBo responseBo = ficheProductBusiness.UpdateProducts(ficheBo); responseDto = responseBo.ToResponseDto(); return(responseDto); }
public ResponseDto Save(FicheDto ficheDto) { ResponseDto responseDto = new ResponseDto(); if (ficheDto == null) { responseDto.IsSuccess = false; responseDto.Message = Business.Stc.GetDicValue("xInvalidData", Session.RealPerson.LanguageId); return(responseDto); } if ((ficheDto.FicheTypeId == Enums.FicheTypes.xReceipt || ficheDto.FicheTypeId == Enums.FicheTypes.xInvoice) && (ficheDto.ProductList == null || ficheDto.ProductList.Count() == 0)) { responseDto.IsSuccess = false; responseDto.Message = Business.Stc.GetDicValue("xNoProduct", Session.RealPerson.LanguageId); return(responseDto); } if (ficheDto.IssueDateNumber < 0 || (ficheDto.DueDateNumber != null && ficheDto.DueDateNumber.Value < 0)) { responseDto.IsSuccess = false; responseDto.Message = Business.Stc.GetDicValue("xInvalidDate", Session.RealPerson.LanguageId); return(responseDto); } FicheBo ficheBo = new FicheBo() { Id = ficheDto.Id, DebtPersonId = ficheDto.DebtPersonId, CreditPersonId = ficheDto.CreditPersonId, FicheTypeId = ficheDto.FicheTypeId, CurrencyId = ficheDto.CurrencyId, // FicheStatId sp will decide it. IncludingVat = ficheDto.IncludingVat, PrintedCode = ficheDto.PrintedCode, IssueDate = ficheDto.IssueDateNumber.ToDateTimeFromNumber(), DueDate = ficheDto.DueDateNumber.ToDateTimeFromNumberNull(), UnderDiscountRate = ficheDto.UnderDiscountRate, UnderDiscountTotal = ficheDto.UnderDiscountTotal, FicheContentId = ficheDto.FicheContentId, FicheContentGroupId = ficheDto.FicheContentGroupId, Notes = ficheDto.Notes, AcceptorPersonId = ficheDto.AcceptorPersonId, OrderId = ficheDto.OrderId, IsUncompleted = ficheDto.IsUncompleted, GrandTotal = ficheDto.GrandTotal, // Will not be calculated in case of fiche type is 'xDebtCredit'. Session = Session // Business will calculate below values: // GrandTotal // Total // RowDiscountTotal // UnderDiscountTotal // VatTotal }; if (ficheDto.MoneyList != null && ficheDto.MoneyList.Count > 0) { ficheBo.MoneyList = (from x in ficheDto.MoneyList select new FicheMoneyBo { Id = x.Id, DebtPersonAccountId = x.DebtPersonAccountId, CreditPersonAccountId = x.CreditPersonAccountId, Total = x.Total, DebtPersonAccountTypeId = x.DebtPersonAccountTypeId, CreditPersonAccountTypeId = x.CreditPersonAccountTypeId, Notes = x.Notes }).ToList(); } if (ficheDto.ProductList != null && ficheDto.ProductList.Count > 0) { // ficheDto.ProductList.Count() foreach (var line in ficheDto.ProductList.Where(w => !w.IsDeleted).GroupBy(info => info.ProductId) .Select(group => new { Metric = group.Key, Count = group.Count() }) .OrderBy(x => x.Metric)) { if (line.Count > 1) { responseDto.IsSuccess = false; responseDto.Message = "Birden fazla aynı ürün var hacı."; return(responseDto); } } ficheBo.ProductList = (from x in ficheDto.ProductList //where !x.IsDeleted select new FicheProductBo { Id = x.Id, ProductId = x.ProductId, Quantity = x.Quantity, UnitPrice = x.UnitPrice, DiscountRate = x.DiscountRate, DiscountTotal = x.DiscountTotal, VatRate = x.VatRate, Notes = x.Notes, IsDeleted = x.IsDeleted // Business will calculate below values: // Total // Discount total // VatTotal // GrandTotal }).ToList(); } if (ficheDto.RelationList != null && ficheDto.RelationList.Count > 0) { ficheBo.RelationList = (from x in ficheDto.RelationList select new FicheRelationSaveBo { ChildFicheId = x.ChildFicheId, FicheRelationTypeId = x.FicheRelationTypeId }).ToList(); } // No need to pass the 'VatTotalList'. Because business will calculate it. ResponseBo responseBo = ficheBusiness.Save(ficheBo); base.SendNotifyWsToList(responseBo.PersonNotifyList); responseDto = responseBo.ToResponseDto(); return(responseDto); }