public static Item ToDALItem(this ItemFixed item, int retailerId, JobAudit job, DataErrorDAL dataErrorDAL) { if (item == null) { return(null); } try { string sDepIp = item.DepartmentID.RemoveTrailComma(); int depId = 0; if (!string.IsNullOrEmpty(sDepIp)) { depId = Convert.ToInt32(sDepIp); } Item result = new Item { RetailerId = retailerId, SKU = item.ItemID.ToLong(), Description = item.ReceiptDescription.RemoveTrailCommaAndSanitize(), DepartmentId = item.DepartmentID.ToNullableInt(), PriceGroup = item.PriceGroupId.ToInt(), ProductGroup = item.MixMatchIdFiveDigit.ToInt(), Category7 = item.FoodStampFlag.ToBool(), Category8 = item.NoneMerchandiseID.ToBool(), Category9 = item.StoreCouponFlag.ToBool(), Category10 = item.WICFlag.ToBool(), Size = item.Size.RemoveTrailComma(), Unit = item.Unit.RemoveTrailComma(), CurrentUnitPrice = item.CenterPrice.ToDouble(), QtyPrice = item.RetailPrice.ToDouble(), QtyBreak = item.UnitQuantity.ToInt() }; return(result); } catch (Exception ex) { Logger.LogException(ex); DataError dataError = new DataError { RetailerId = retailerId, Source = InputFileType.Items, ElementId = item.ItemID.ToLong(), Note = "Items file parse error! Row is wrongly formatted!" }; dataErrorDAL.InsertDataError(dataError); job.IncrementError(1); return(null); } }
private void UpdateDB(List <Department> fromClient, List <Department> fromDB) { if (fromClient == null || fromDB == null || fromClient.Count == 0) { return; } // we parse all the items and populate the status field // we do this if for optimization if (fromClient.Count > fromDB.Count) { foreach (Department dept in fromClient) { if (dept == null) { continue; } Department dbDept = fromDB.Where(dDB => dDB.Id == dept.Id).FirstOrDefault(); if (dbDept == null) { dept.Status = ElementStatus.New; int errorCount = DeptDAL.InsertDepartment(dept); _job.IncrementError(errorCount); _job.IncrementNew(errorCount); continue; } if (dept.DifferFrom(dbDept)) { dbDept.Status = dept.Status = ElementStatus.Update; int errorCount = DeptDAL.UpdateDepartment(dept, dbDept); _job.IncrementError(errorCount); _job.IncrementUpdated(errorCount); continue; } else { dbDept.Status = dept.Status = ElementStatus.Unchanged; continue; } } fromDB .Where(d => d.Status == null) .ToList() .ForEach(d => { if (d.DateRemoved == null) { d.Status = ElementStatus.Delete; int errorCount = DeptDAL.DeleteDepartment(d.RetailerId, d.Id); _job.IncrementError(errorCount); _job.IncrementUpdated(errorCount); } }); } else { foreach (Department dept in fromDB) { Department clientDept = fromClient.Where(d => d.Id == dept.Id).FirstOrDefault(); if (clientDept == null) { if (dept.DateRemoved == null) { dept.Status = ElementStatus.Delete; int errorCount = DeptDAL.DeleteDepartment(dept.RetailerId, dept.Id); _job.IncrementError(errorCount); _job.IncrementDeleted(errorCount); } continue; } if (dept.DifferFrom(clientDept)) { clientDept.Status = dept.Status = ElementStatus.Update; int errorCount = DeptDAL.UpdateDepartment(clientDept, dept); _job.IncrementError(errorCount); _job.IncrementUpdated(errorCount); continue; } else { clientDept.Status = dept.Status = ElementStatus.Unchanged; continue; } } fromClient .Where(d => d.Status == null) .ToList() .ForEach(d => { d.Status = ElementStatus.New; int errorCount = DeptDAL.InsertDepartment(d); _job.IncrementError(errorCount); _job.IncrementNew(errorCount); }); } }
private void UpdateDB(List <Item> fromClient, List <Item> fromDB) { if (fromClient == null || fromDB == null || fromClient.Count == 0) { return; } // we parse all the items and populate the status field // we do this if for optimization if (fromClient.Count > fromDB.Count) { foreach (Item item in fromClient) { if (item == null) { continue; } Item dbItem = fromDB.Where(iDB => iDB.SKU == item.SKU).FirstOrDefault(); if (dbItem == null) { item.Status = ElementStatus.New; int errorCount = ItmDAL.InsertItem(item); _job.IncrementError(errorCount); _job.IncrementNew(errorCount); continue; } if (item.DifferFrom(dbItem)) { dbItem.Status = item.Status = ElementStatus.Update; int errorCount = ItmDAL.UpdateItem(item, dbItem); _job.IncrementError(errorCount); _job.IncrementUpdated(errorCount); continue; } else { dbItem.Status = item.Status = ElementStatus.Unchanged; continue; } } fromDB .Where(i => i.Status == null) .ToList() .ForEach(i => { if (i.DateRemoved == null) { i.Status = ElementStatus.Delete; int errorCount = ItmDAL.DeleteItem(i.RetailerId, i.SKU); _job.IncrementError(errorCount); _job.IncrementDeleted(errorCount); } }); } else { foreach (Item item in fromDB) { Item clientItem = fromClient.Where(i => i != null && item != null && i.SKU == item.SKU).FirstOrDefault(); if (clientItem == null) { if (item.DateRemoved == null) { item.Status = ElementStatus.Delete; int errorCount = ItmDAL.DeleteItem(item.RetailerId, item.SKU); _job.IncrementError(errorCount); _job.IncrementDeleted(errorCount); } continue; } if (item.DifferFrom(clientItem)) { clientItem.Status = item.Status = ElementStatus.Update; int errorCount = ItmDAL.UpdateItem(clientItem, item); _job.IncrementError(errorCount); _job.IncrementUpdated(errorCount); continue; } else { clientItem.Status = item.Status = ElementStatus.Unchanged; continue; } } fromClient .Where(i => i != null && i.Status == null) .ToList() .ForEach(i => { i.Status = ElementStatus.New; int errorCount = ItmDAL.InsertItem(i); _job.IncrementError(errorCount); _job.IncrementNew(errorCount); }); } }