public async Task <IActionResult> OnGetAsync(int?id, int?parentid) { if (id == null & parentid == null) { return(NotFound()); } if ((parentid ?? 0) > 0) { id = CreateRequestFromParent(parentid.Value); return(RedirectToPage("./edit", new { id = id })); } CustomerRequest = await _context.CustomerRequests .Include(c => c.Customer) .Include(c => c.Program) .ThenInclude(c => c.ElementntTypes) .Include(c => c.RequestElementTypes) .ThenInclude(c => c.ElementType) .Include(c => c.Program) .ThenInclude(c => c.Templates) .FirstOrDefaultAsync(m => m.CustomerRequestID == id); ElementImport = _context.ElementImports .FirstOrDefault(m => m.CustomerRequest.CustomerRequestID == id); // запролняем типы элементов PopulateAssignedElementTypes(CustomerRequest); //Заполняем операции PopulateOperations(CustomerRequest); if (CustomerRequest == null) { return(NotFound()); } // Добавляем типы элементов для новой заявки ViewData["CustomerID"] = new SelectList(_context.Customers.OrderBy(e => e.Name), "CustomerID", "Name"); ViewData["TestProgramID"] = new SelectList(_context.TestPrograms, "TestProgramID", "Name"); ViewData["TestProgramTemplateID"] = new SelectList(CustomerRequest.Program.Templates, "TestProgramTemplateID", "TemplateName"); return(Page()); }
public async Task <IActionResult> OnGetAsync(int?id, int?step) { if (id == null) { return(NotFound()); } //установка шага 1 если шаг не задан ImportStep = step == null ? 1 : step.Value; ElementImport = _context.ElementImports .FirstOrDefault(m => m.CustomerRequest.CustomerRequestID == id); //не нашли такого файла импорта if (ElementImport == null) { ElementImport = new ElementImport { XLSXElementTypes = new List <XLSXElementType>(), CustomerRequestID = id.Value }; ElementImport.CustomerRequest = _context.CustomerRequests .Include(c => c.Customer) .Include(c => c.Program) .ThenInclude(c => c.ElementntTypes) .ThenInclude(c => c.Keys) .FirstOrDefault(m => m.CustomerRequestID == id); } else { ElementImport = _context.ElementImports .Include(e => e.XLSXElementTypes) .FirstOrDefault(m => m.CustomerRequest.CustomerRequestID == id); if (ValidateXLSX(false)) { if (ImportStep != -1) { ImportStep = 3; FillELementTypes(); } else { ImportStep = 1; //если пытаемся заного загрузить файл, когда уже 1 раз загрузили if (ElementImport.XLSXElementTypes != null) { if (ElementImport.XLSXElementTypes.Count > 0) { ErrorMessage = "Если вы загрузите новый файл, старые значения будут стерты!"; } } } } else { ElementImport.XLSXElementTypes = ElementImport.XLSXElementTypes.OrderBy(e => e.Valid).ToList(); } } return(Page()); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync(int?id, AssignedRequestElementType[] elementTypes, RequestOperationGroupView[] requestOperationGroupViews) { if (!ModelState.IsValid) { var errors = ModelState.Values.SelectMany(v => v.Errors); return(Page()); } if (id == null) { return(NotFound()); } //Элемент импорт тоже пригодиться ElementImport = _context.ElementImports .AsNoTracking() .FirstOrDefault(m => m.CustomerRequest.CustomerRequestID == id); //получаем текущую заявку var requestToUpdate = await _context.CustomerRequests .Include(c => c.Customer) .Include(c => c.Program) .ThenInclude(c => c.ElementntTypes) .Include(c => c.Program) .ThenInclude(e => e.Templates) .Include(c => c.RequestElementTypes) .ThenInclude(c => c.ElementType) .Include(c => c.RequestElementTypes) .ThenInclude(c => c.RequestOperations) .ThenInclude(c => c.TestChainItem) .FirstOrDefaultAsync(m => m.CustomerRequestID == id); requestToUpdate.ModificateDate = System.DateTime.Now; if (UserID > 0) { requestToUpdate.LastModificateUserID = UserID; } if (requestToUpdate == null) { // заявка не найдена return(NotFound()); } // Обновляет извлеченную сущность CustomerRequest, используя значения из связывателя модели. TryUpdateModel позволяет предотвратить чрезмерную передачу данных. if (await TryUpdateModelAsync <CustomerRequest>( requestToUpdate, "CustomerRequest", i => i.RequestNumber, i => i.RequestDate, i => i.CustomerID, i => i.Description, i => i.UseTemplate, i => i.TestProgramTemplateID) ) { UpdateAssignedElementTypes(elementTypes, requestToUpdate); if (requestToUpdate.Program.AllowEditChain) { UpdateRequestOperations(requestOperationGroupViews, requestToUpdate); } await _context.SaveChangesAsync(); return(RedirectToPage("./edit", new { id = id })); } else { // не получилось обновить PopulateAssignedElementTypes(requestToUpdate); return(Page()); } }
public IHttpActionResult Import(ElementImport entity) { var element = ServiceContext.ElementService.GetByIDItemSite(entity.ID); if (element == null) { var customer = ServiceContext.CustomerService.GetInsert(entity.Customer.Name, "-", "-", entity.Customer.Email, entity.Customer.Phone, entity.Customer.ID, entity.Customer.Logo); var purpose = ServiceContext.PurposeService.GetInsert(entity.PurposeName); var category = ServiceContext.HierarchyStructureService.GetInsert(entity.CategoryName, purpose.IDPurpose); var stateProvice = ServiceContext.StateProvinceService.GetInsert(entity.StateProvinceName, entity.CountryName); var city = ServiceContext.CityService.GetInsert(entity.CityName, stateProvice.IDStateProvince.Value); element = new Element() { IDCity = city.IDCity.Value, IDCustomer = customer.IDCustomer.Value, IDPurpose = purpose.IDPurpose.Value, IDHierarchyStructure = category.IDHierarchyStructure.Value, IDHierarchyStructureParent = category.IDHierarchyStructure.Value, Address = entity.Address ?? "-", AllowRatting = true, CreateDate = DateTime.Now, CreatedBy = "IMPORT", ModifiedBy = "IMPORT", ModifyDate = DateTime.Now, DefaultPicturePath = entity.DefaultPicture, DetailView = 0, IDItemSite = entity.ID, IsPromoted = false, Neighborhood = entity.Neighborhood, Latitude = entity.Latitude, Longitude = entity.Longitude, PageView = 0, ShowAddress = true, Url = entity.Url, Status = (short)Enums.StatusType.Active }; } //carregando cultures var elementCulture = new List <ElementCulture>(); foreach (var item in ServiceContext.CultureService.GetAllActive()) { elementCulture.Add(new ElementCulture() { Description = entity.Description, Name = entity.Title, IDCulture = item.IDCulture }); } // //carregando elementos var elementAttribute = new List <ElementAttribute>(); foreach (var item in entity.Attributes) { elementAttribute.Add(new ElementAttribute() { IDAttribute = ServiceContext.AttributeService.GetInsert(item.Name), Value = item.Value }); } //carregando images var elementImages = new List <string>(); foreach (var item in entity.Images) { //if(item.IsMain) // elementImages.Add(item.UrlImageMain); //else // elementImages.Add(item.UrlImageSize4); elementImages.Add(item.UrlImageSize4); } if (!element.IDElement.HasValue) { ServiceContext.ElementService.Insert(element, elementCulture, elementAttribute, elementImages); return(Ok(new { Message = "OK", Action = "Insert", id = element.IDItemSite })); } else { ServiceContext.ElementService.Update(element, elementCulture, elementAttribute, elementImages); return(Ok(new { Message = "OK", Action = "Update", id = element.IDItemSite })); } }
private void FillDefectedTypes() { //получаем список элементов ElementImport = _context.ElementImports .Include(e => e.XLSXElementTypes) .FirstOrDefault(m => m.CustomerRequest.CustomerRequestID == CustomerRequest.CustomerRequestID); //если нет импорта то и нет элементов if (ElementImport == null) { return; } ElementImport.XLSXElementTypes = ElementImport.XLSXElementTypes.OrderBy(s => s.ElementImportID).ToList(); ElementImport.CustomerRequest = CustomerRequest; // вычисляем стоимость испытаний 1 шт foreach (XLSXElementType type in ElementImport.XLSXElementTypes) { foreach (RequestElementType requestType in CustomerRequest.RequestElementTypes) { if (requestType.ElementTypeID == type.ElementTypeID) { type.ElementTypeName = requestType.ElementType.Name; type.Cost = (requestType.CostSummary / requestType.ItemCount) * type.ElementCount; } } } Dictionary <Int64, DefectedType> returnTypes = new Dictionary <Int64, DefectedType>(); SetAsuContext(); // List<XLSXElementType> list = _context.XLSXElementTypes.FromSqlRaw(selectStr, PrepareStr(elementName), id, programid).ToList(); ElementImport.DefectedTypes = new System.Collections.Generic.List <DefectedType>(); foreach (XLSXElementType type in ElementImport.XLSXElementTypes) { string selectStr = "select d.DefectId as ID, l.PrefixNumber + '-' + CAST(l.Number AS VARCHAR(32)) + (CASE WHEN(l.SuffixNumber IS NULL) " + "THEN('') ELSE l.SuffixNumber END) AS[ProtokolNumber], w.TypeNominal , w.TU1 + ' ' + w.TU2 AS[TY], d.[Description], " + "d.TU as NormTY, d.Unrecommend , d.RFA, d.DefectCount as DefectCount " + "from Defect d,[dbo].[RouteOperation] r, lot l, Wares w " + "where r.RouteOperationId = d.RouteOperationId and l.LotId = r.LotId and w.WareId = l.WareId " + "and w.TypeNominal like N'{0}'"; string elementName = type.ElementName.Trim().Substring(0, type.ElementName.Trim().Length > 15?15:type.ElementName.Trim().Length); selectStr = String.Format(selectStr, elementName); System.Collections.Generic.List <DefectedType> defTypes = _asuContext.DefectedTypes.FromSqlRaw(selectStr).ToList(); foreach (DefectedType item in defTypes) { if (!returnTypes.ContainsKey(item.ID)) { returnTypes.Add(item.ID, item); } } ElementImport.DefectedTypes.AddRange(defTypes); } ElementImport.DefectedTypes = returnTypes.Values.ToList(); }