/// <summary> /// Add Title in VID /// </summary> /// <param name="vid">This consists of all the required information need to form VID object which is further inserted into the database</param> /// <returns>Save Result</returns> public SaveResult Save(VID vid) { var _context = new DeluxeOrderManagementEntities(); _context.VIDs.Add(vid); _context.SaveChanges(); return(new SaveResult()); }
/// <summary> /// Create Order in the system /// </summary> /// <param name="order">Details of new order</param> /// <param name="assets">List of assets for new order</param> /// <returns>Order creation status</returns> public OrderSaveStatus CreateOrder(Order order, List <string> assets) { OrderSaveStatus orderStatus = new OrderSaveStatus(); var _context = new DeluxeOrderManagementEntities(); int languageId = Convert.ToInt32(order.Language); int territoryId = Convert.ToInt32(order.Territory); var announcement = (from ann in _context.AnnouncementGrids where ann.VideoVersion == order.Title && ann.LanguageId == languageId && ann.TerritoryId == territoryId select ann).FirstOrDefault(); if (announcement != null) { var orders = (from og in _context.OrderGrids where og.AnnouncementId == announcement.Id && assets.Contains(og.LanguageType) select og).ToList(); var vids = (from v in _context.VIDs where (v.VendorId == order.VendorId || string.IsNullOrEmpty(v.VendorId)) && v.VideoVersion == announcement.VideoVersion select v ).FirstOrDefault(); VID vid = null; //if (orders.Count == 0 || orders == null) //{ if (vids == null) { vid = new VID(); vid.VIDStatus = "PRIMARY"; vid.VendorId = order.VendorId; vid.VideoVersion = announcement.VideoVersion; vid.TitleName = announcement.Title; vid.TitleCategory = order.OrderCategory; vid.EditName = announcement.LocalEdit; vid.CreatedOn = DateTime.UtcNow; vid.ModifiedOn = DateTime.UtcNow; vid.CreatedBy = "Deluxe"; vid.ModifiedBy = "Deluxe"; _context.VIDs.Add(vid); //_context.SaveChanges(); } else { vids.VendorId = order.VendorId; } foreach (var asset in assets) { OrderGrid orderGrid = new OrderGrid() { AnnouncementId = announcement.Id, OrderStatus = order.OrderStatus, MPO = order.MPO, HALID = order.HALID, Category = order.OrderCategory, RequestNumber = order.RequestNumber, DeliveryDueDate = ParseDate(order.DueDate), GreenlightSenttoPackaging = ParseDate(order.GreenlightSent), GreenlightValidatedbyDMDM = ParseDate(order.GreenlightReceived), ActualDeliveryDate = ParseDate(order.DeliveryDate), ESTUPC = order.ESTUPC, IVODUPC = order.VODUPC, LanguageType = asset, FileType = order.OrderType, CustomerId = 1, VendorId = order.VendorId//(vid != null) ? vid.VendorId : vids.FirstOrDefault().VendorId }; _context.OrderGrids.Add(orderGrid); _context.SaveChanges(); _context.usp_UpdateOG_Status(orderGrid.Id.ToString()); } orderStatus.ErrorMessage = Constant.orderSaved; orderStatus.IsSaved = true; orderStatus.IsAnnouncementExist = true; //} //else //{ // orderStatus.ErrorMessage = Constant.orderExist; // orderStatus.IsSaved = false; // orderStatus.IsAnnouncementExist = true; //} } else if (announcement == null && !string.IsNullOrEmpty(order.LocalEdit)) { string title = _context.VIDs.Where(x => x.VideoVersion == order.Title).Select(x => x.TitleName).FirstOrDefault(); AnnouncementGrid newAnnouncement = new AnnouncementGrid() { VideoVersion = order.Title, Title = title, LanguageId = languageId, TerritoryId = territoryId, LocalEdit = order.LocalEdit, CustomerId = 1, JObId = 0 }; _context.AnnouncementGrids.Add(newAnnouncement); _context.SaveChanges(); var orders = (from og in _context.OrderGrids where og.AnnouncementId == newAnnouncement.Id && assets.Contains(og.LanguageType) select og).ToList(); var vids = (from v in _context.VIDs where v.VendorId == order.VendorId && v.VideoVersion == newAnnouncement.VideoVersion select v ).FirstOrDefault(); VID vid = null; //if (orders.Count == 0 || orders == null) //{ if (vids == null) { vid = new VID(); vid.VIDStatus = "PRIMARY"; vid.VendorId = order.VendorId; vid.VideoVersion = newAnnouncement.VideoVersion; vid.TitleName = newAnnouncement.Title; vid.TitleCategory = order.OrderCategory; vid.EditName = newAnnouncement.LocalEdit; vid.CreatedOn = DateTime.UtcNow; vid.ModifiedOn = DateTime.UtcNow; vid.CreatedBy = "Deluxe"; vid.ModifiedBy = "Deluxe"; _context.VIDs.Add(vid); _context.SaveChanges(); } else { vids.VendorId = order.VendorId; } foreach (var asset in assets) { OrderGrid orderGrid = new OrderGrid() { AnnouncementId = newAnnouncement.Id, OrderStatus = order.OrderStatus, MPO = order.MPO, HALID = order.HALID, Category = order.OrderCategory, RequestNumber = order.RequestNumber, DeliveryDueDate = ParseDate(order.DueDate), GreenlightSenttoPackaging = ParseDate(order.GreenlightSent), GreenlightValidatedbyDMDM = ParseDate(order.GreenlightReceived), ActualDeliveryDate = ParseDate(order.DeliveryDate), ESTUPC = order.ESTUPC, IVODUPC = order.VODUPC, LanguageType = asset, CustomerId = 1, VendorId = order.VendorId//(vid != null) ? vid.VendorId : vids.FirstOrDefault().VendorId }; _context.OrderGrids.Add(orderGrid); _context.SaveChanges(); _context.usp_UpdateOG_Status(orderGrid.Id.ToString()); } orderStatus.ErrorMessage = Constant.announcementNotExist; orderStatus.IsSaved = true; orderStatus.IsAnnouncementExist = false; //} //else //{ // orderStatus.ErrorMessage = Constant.orderExist; // orderStatus.IsSaved = false; // orderStatus.IsAnnouncementExist = false; //} } else { orderStatus.ErrorMessage = Constant.announcementNotExist; orderStatus.IsSaved = false; orderStatus.IsAnnouncementExist = false; } return(orderStatus); }
/// <summary> /// Edit and save selected order /// </summary> /// <param name="order">order contains all details of the order which is selected for edit</param> /// <returns>True if order updated else false</returns> public bool EditOrder(Order order) { bool status = false; var _context = new DeluxeOrderManagementEntities(); VID vid = new VID(); var announcement = (from ann in _context.AnnouncementGrids where ann.Id == order.AnnouncemntId select ann).FirstOrDefault(); var vidEty = (from vids in _context.VIDs where (vids.VendorId == order.VendorId || string.IsNullOrEmpty(vids.VendorId)) && vids.VideoVersion == announcement.VideoVersion select vids).FirstOrDefault(); if (vidEty == null) { vid.VIDStatus = "PRIMARY"; vid.VendorId = order.VendorId; vid.VideoVersion = announcement.VideoVersion; vid.TitleName = announcement.Title; vid.TitleCategory = order.OrderCategory; vid.EditName = announcement.LocalEdit; vid.CreatedOn = DateTime.UtcNow; vid.ModifiedOn = DateTime.UtcNow; vid.CreatedBy = "Deluxe"; vid.ModifiedBy = "Deluxe"; _context.VIDs.Add(vid); status = true; } else { vidEty.VendorId = order.VendorId; status = true; } var ety = _context.OrderGrids.Where(x => x.Id == order.OrderId).FirstOrDefault(); if (ety != null) { ety.RequestNumber = order.RequestNumber; ety.HALID = order.HALID; ety.MPO = order.MPO; ety.DeliveryDueDate = ParseDate(order.DueDate); ety.GreenlightSenttoPackaging = ParseDate(order.GreenlightSent); ety.GreenlightValidatedbyDMDM = ParseDate(order.GreenlightReceived); ety.ActualDeliveryDate = ParseDate(order.DeliveryDate); ety.ESTUPC = order.ESTUPC; ety.IVODUPC = order.VODUPC; ety.Category = order.OrderCategory; ety.OrderStatus = order.OrderStatus; ety.VendorId = order.VendorId; ety.FileType = order.OrderType; //ety.VIDId = (orders.Count == 1 /*|| orderExceptCurrent.Count==1*/) ? vidEty.Id : vid.Id; status = true; } if (status) { _context.SaveChanges(); if (string.IsNullOrEmpty(order.OrderStatus) || !order.OrderStatus.Equals("Other Vendor")) { _context.usp_UpdateOG_Status(order.OrderId.ToString()); } } return(status); }