public void DTO2DB_PurchaseQuatation(DTO.PurchaseQuotationDTO dtoItem, ref PurchaseQuotation dbItem) { if (dtoItem.PurchaseQuotationDetailDTOs != null) { foreach (var item in dbItem.PurchaseQuotationDetail.ToArray()) { if (!dtoItem.PurchaseQuotationDetailDTOs.Select(s => s.PurchaseQuotationDetailID).Contains(item.PurchaseQuotationDetailID)) { dbItem.PurchaseQuotationDetail.Remove(item); } } foreach (var item in dtoItem.PurchaseQuotationDetailDTOs) { PurchaseQuotationDetail dbDetail = new PurchaseQuotationDetail(); if (item.PurchaseQuotationDetailID < 0) { dbItem.PurchaseQuotationDetail.Add(dbDetail); } else { dbDetail = dbItem.PurchaseQuotationDetail.Where(s => s.PurchaseQuotationDetailID == item.PurchaseQuotationDetailID).FirstOrDefault(); } if (dbDetail != null) { AutoMapper.Mapper.Map <DTO.PurchaseQuotationDetailDTO, PurchaseQuotationDetail>(item, dbDetail); } } } AutoMapper.Mapper.Map <DTO.PurchaseQuotationDTO, PurchaseQuotation>(dtoItem, dbItem); dbItem.ValidFrom = dtoItem.ValidFrom.ConvertStringToDateTime(); dbItem.ValidTo = dtoItem.ValidTo.ConvertStringToDateTime(); }
public override bool Approve(int userId, int id, ref object dtoItem, out Notification notification) { notification = new Notification(); notification.Type = NotificationType.Success; try { using (var context = CreatContext()) { PurchaseQuotation dbItem = context.PurchaseQuotation.FirstOrDefault(o => o.PurchaseQuotationID == id); if (dbItem == null) { notification.Type = NotificationType.Error; notification.Message = "Can not find data!"; return(false); } dbItem.IsApproved = true; dbItem.ApprovedBy = userId; dbItem.ApprovedDate = DateTime.Now; context.SaveChanges(); dtoItem = GetData(dbItem.PurchaseQuotationID, out notification).Data; SendMailToNotificationGroup(dbItem); } } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; return(false); } return(true); }
void SendMailToNotificationGroup(PurchaseQuotation dbItem) { using (var context = CreatContext()) { List <int?> NotificationGroupMembers = context.NotificationGroupMember.Where(x => x.NotificationGroup.NotificationGroupUD == "PQG").Select(y => y.UserID).ToList(); var employees = context.Employee.Where(x => NotificationGroupMembers.Contains(x.UserID)).Select(y => new { y.Email1, y.UserID }).ToList(); string Subject = string.Format("[Tilsoft] - Purchasing Quotation - {0} - {1}", dbItem.PurchaseQuotationUD, dbItem.FactoryRawMaterial.FactoryRawMaterialShortNM); string Content = string.Format("Please approve PQ: {0} - {1} - {2}", dbItem.PurchaseQuotationUD, dbItem.FactoryRawMaterial.FactoryRawMaterialShortNM, "http://app.tilsoft.bg/PurchaseQuotationMng/Edit/" + dbItem.PurchaseQuotationID); string sendToEmail = string.Empty; foreach (var eAddress in employees) { if (string.IsNullOrEmpty(sendToEmail)) { sendToEmail += eAddress; } else { sendToEmail += ";" + eAddress; } // add to NotificationMessage table NotificationMessage notification = new NotificationMessage(); notification.UserID = eAddress.UserID; notification.NotificationMessageTag = Module.Framework.ConstantIdentifier.MOBILE_APP_MESSAGE_TAG_PURCHASING; notification.NotificationMessageTitle = Subject; notification.NotificationMessageContent = Content; context.NotificationMessage.Add(notification); } EmailNotificationMessage dbEmail = new EmailNotificationMessage(); dbEmail.EmailBody = Content; dbEmail.EmailSubject = Subject; dbEmail.SendTo = sendToEmail; context.EmailNotificationMessage.Add(dbEmail); context.SaveChanges(); } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification) { notification = new Notification { Type = NotificationType.Success }; DTO.PurchaseQuotationDTO dtoPurchaseQuotation = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.PurchaseQuotationDTO>(); try { // 1. Check validation validFrom and validTo var validFrom = dtoPurchaseQuotation.ValidFrom.ConvertStringToDateTime(); var validTo = dtoPurchaseQuotation.ValidTo.ConvertStringToDateTime(); // 1.1. Case validFrom not value if (!validFrom.HasValue) { notification.Type = NotificationType.Error; notification.Message = "Valid From is invalid!"; return(false); } // 1.2. Compare if (validTo.HasValue) { if (validTo.Value.CompareTo(validFrom.Value) < 0) { notification.Type = NotificationType.Error; notification.Message = "Valid From is less than Valid To!"; return(false); } } using (var context = CreatContext()) { PurchaseQuotation dbItem; if (id == 0) { dbItem = new PurchaseQuotation(); context.PurchaseQuotation.Add(dbItem); } else { dbItem = context.PurchaseQuotation.Where(o => o.PurchaseQuotationID == id).FirstOrDefault(); } if (dbItem == null) { notification.Type = NotificationType.Error; notification.Message = "Data Not Found !"; return(false); } else { //converter converter.DTO2DB_PurchaseQuatation(dtoPurchaseQuotation, ref dbItem); //upload file Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); string tempFolder = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\"; if (dtoPurchaseQuotation.File_HasChange.HasValue && dtoPurchaseQuotation.File_HasChange.Value) { dbItem.AttachedFile = fwFactory.CreateFilePointer(tempFolder, dtoPurchaseQuotation.File_NewFile, dtoPurchaseQuotation.AttachedFile, dtoPurchaseQuotation.FriendlyName); } //Remove context.PurchaseQuotationDetail.Local.Where(o => o.PurchaseQuotation == null).ToList().ForEach(o => context.PurchaseQuotationDetail.Remove(o)); int?companyID = fwFactory.GetCompanyID(userId); dbItem.CompanyID = companyID; dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; if (id == 0) { dbItem.PurchaseQuotationUD = context.PurchaseQuotationMng_function_GeneratePurchaseQuotationUD().FirstOrDefault(); dbItem.CreatedBy = userId; dbItem.CreatedDate = DateTime.Now; } /// cuong.tran: ProductionFrameWeight - start foreach (var item in dtoPurchaseQuotation.PurchaseQuotationDetailDTOs) { /// Only material is component if (item.ProductionItemTypeID == 1 && item.FrameWeight.HasValue) { var dtoFrameWeight = context.ProductionFrameWeight.FirstOrDefault(o => o.ProductionItemID == item.ProductionItemID); if (dtoFrameWeight == null) { // Insert table ProductionFrameWeight ProductionFrameWeight dbFrameWeight = new ProductionFrameWeight(); context.ProductionFrameWeight.Add(dbFrameWeight); dbFrameWeight.ProductionItemID = item.ProductionItemID; dbFrameWeight.FrameWeight = item.FrameWeight; dbFrameWeight.UpdatedBy = userId; dbFrameWeight.UpdatedDate = DateTime.Now; context.SaveChanges(); // Insert table ProductionFrameWeightHistory ProductionFrameWeightHistory dbFrameWeightHistory = new ProductionFrameWeightHistory(); context.ProductionFrameWeightHistory.Add(dbFrameWeightHistory); dbFrameWeightHistory.ProductionFrameWeightID = dbFrameWeight.ProductionFrameWeightID; dbFrameWeightHistory.FrameWeight = item.FrameWeight; dbFrameWeightHistory.UpdatedBy = userId; dbFrameWeightHistory.UpdatedDate = DateTime.Now; context.SaveChanges(); } } } /// cuong.tran: ProductionFrameWeight - e n d //Save context.SaveChanges(); dtoItem = GetData(dbItem.PurchaseQuotationID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; return(false); } }