public async Task <IHttpActionResult> PostDocSecondHandRazbor2Tab(DocSecondHandRazbor2Tab docSecondHandRazbor2Tab, HttpRequestMessage request) { //Алгоритм //1. DirNomens (ищим: находим (ничего), не находим (новый)) и заполняем DocSecondHandRazbor2Tabs.DirNomenID //2. DocSecondHandRazbor2Tabs (сохраняем) //3. Партии (создаём партию) try { #region Проверяем Логин и Пароль + Изменяем строку соединения + Права + Разные Функции //Получаем Куку System.Web.HttpCookie authCookie = System.Web.HttpContext.Current.Request.Cookies["CookieIPOL"]; // Проверяем Логин и Пароль Classes.Account.Login.Field field = await Task.Run(() => login.Return(authCookie, true)); if (!field.Access) { return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg10))); } //Изменяем строку соединения db = new DbConnectionSklad(connectionString.Return(field.DirCustomersID, null, true)); dbRead = new DbConnectionSklad(connectionString.Return(field.DirCustomersID, null, true)); //Права (1 - Write, 2 - Read, 3 - No Access) int iRight = await Task.Run(() => accessRight.Access(connectionString.Return(field.DirCustomersID, null, true), field.DirEmployeeID, "RightDocSecondHandRazbors")); if (iRight != 1) { return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg57(0)))); } //Разные Функции function.NumberDecimalSeparator(); //Получам настройки sysSetting = await db.SysSettings.FindAsync(1); #endregion #region Параметры //save, save_close, held, held_cancel var paramList = request.GetQueryNameValuePairs(); docSecondHandRazbor2Tab.DocSecondHandPurchID = Convert.ToInt32(paramList.FirstOrDefault(kv => string.Compare(kv.Key, "DocSecondHandPurchID", true) == 0).Value); #endregion #region Проверки if (!ModelState.IsValid) { return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg91))); //return BadRequest(ModelState); } //Если документ "docSecondHandRazbor2Tab.DocSecondHandPurchID" проведён, то выдать Эксепшн /* * Models.Sklad.Doc.DocSecondHandRazbor docSecondHandRazbor = await db.DocSecondHandRazbors.FindAsync(docSecondHandRazbor2Tab.DocSecondHandPurchID); * //Models.Sklad.Doc.Doc doc = await db.Docs.FindAsync(docSecondHandRazbor.DocID); * if (Convert.ToBoolean(docSecondHandRazbor.doc.Held)) return Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg57_3)); */ Models.Sklad.Doc.DocSecondHandPurch docSecondHandPurch = await db.DocSecondHandPurches.FindAsync(docSecondHandRazbor2Tab.DocSecondHandPurchID); if (docSecondHandPurch == null) { return(Ok(returnServer.Return(false, "Документ (аппарат) не найден №" + docSecondHandRazbor2Tab.DocSecondHandPurchID))); } else { if (docSecondHandPurch.DirSecondHandStatusID != 12) { return(Ok(returnServer.Return(false, "Для добавление запчастей, статус документа должен быть '12.В разборе'. А он " + docSecondHandPurch.DirSecondHandStatusID + "." + docSecondHandPurch.dirSecondHandStatus.DirSecondHandStatusName))); } } //Подстановки - некоторые поля надо заполнить, если они не заполены (Юридические реквизиты) //docSecondHandRazbor2Tab.Substitute(); #endregion #region Сохранение //using (TransactionScope ts = new TransactionScope()) using (System.Data.Entity.DbContextTransaction ts = db.Database.BeginTransaction()) { db.Configuration.AutoDetectChangesEnabled = false; try { //Используем метод, что бы было всё в одном потоке docSecondHandRazbor2Tab = await Task.Run(() => mPutPostDocSecondHandRazbor2Tab(db, dbRead, sysSetting, docSecondHandRazbor2Tab, EntityState.Added, field)); //sysSetting ts.Commit(); //.Complete(); } catch (Exception ex) { try { ts.Rollback(); ts.Dispose(); } catch { } try { db.Database.Connection.Close(); db.Database.Connection.Dispose(); } catch { } return(Ok(returnServer.Return(false, exceptionEntry.Return(ex)))); } } #region 6. JourDisp *** *** *** *** *** *** *** *** *** * Models.Sklad.Sys.SysJourDisp sysJourDisp = new Models.Sklad.Sys.SysJourDisp(); sysJourDisp.DirDispOperationID = 3; //Добавление записи sysJourDisp.DirEmployeeID = field.DirEmployeeID; sysJourDisp.ListObjectID = ListObjectID; sysJourDisp.TableFieldID = docSecondHandRazbor2Tab.DocSecondHandPurchID; sysJourDisp.Description = ""; try { sysJourDispsController.mPutPostSysJourDisps(db, sysJourDisp, EntityState.Added); } catch (Exception ex) { } #endregion dynamic collectionWrapper = new { DocSecondHandRazbor2TabID = docSecondHandRazbor2Tab.DocSecondHandRazbor2TabID }; return(Ok(returnServer.Return(true, collectionWrapper))); //return Ok(returnServer.Return(true, "")); #endregion } catch (Exception ex) { return(Ok(returnServer.Return(false, exceptionEntry.Return(ex)))); } }
//db, dbRead, sysSetting, docSecondHandRazbor2Tab, EntityState.Added, field internal async Task <DocSecondHandRazbor2Tab> mPutPostDocSecondHandRazbor2Tab( DbConnectionSklad db, DbConnectionSklad dbRead, Models.Sklad.Sys.SysSetting sysSetting, DocSecondHandRazbor2Tab docSecondHandRazbor2Tab, EntityState entityState, //EntityState.Added, Modified Classes.Account.Login.Field field //Дополнительные данные о сотруднике ) { //Алгоритм //1. DirNomens (ищим: находим (ничего), не находим (новый)) и заполняем DocSecondHandRazbor2Tabs.DirNomenID //2. DocSecondHandRazbor2Tabs (сохраняем) //3. RemParties (создаём партию) #region 1. DirNomens //Иищим: находим (ничего), не находим (новый) //и заполняем DocSecondHandRazbor2Tabs.DirNomenID #region Категория товара if (docSecondHandRazbor2Tab.DirNomenCategoryID == null) { var queryDirNomenCategoryID = await ( from x in db.DirNomenCategories where x.DirNomenCategoryName == docSecondHandRazbor2Tab.DirNomenCategoryName select x ).ToListAsync(); if (queryDirNomenCategoryID.Count() > 0) { docSecondHandRazbor2Tab.DirNomenCategoryID = queryDirNomenCategoryID[0].DirNomenCategoryID; docSecondHandRazbor2Tab.DirNomenCategoryName = queryDirNomenCategoryID[0].DirNomenCategoryName; } else { Models.Sklad.Dir.DirNomenCategory dirNomenCategory = new Models.Sklad.Dir.DirNomenCategory(); dirNomenCategory.DirNomenCategoryName = docSecondHandRazbor2Tab.DirNomenCategoryName; db.Entry(dirNomenCategory).State = EntityState.Added; await db.SaveChangesAsync(); docSecondHandRazbor2Tab.DirNomenCategoryID = dirNomenCategory.DirNomenCategoryID; docSecondHandRazbor2Tab.DirNomenCategoryName = dirNomenCategory.DirNomenCategoryName; } } else { Models.Sklad.Dir.DirNomenCategory dirNomenCategory = await db.DirNomenCategories.FindAsync(docSecondHandRazbor2Tab.DirNomenCategoryID); docSecondHandRazbor2Tab.DirNomenCategoryName = dirNomenCategory.DirNomenCategoryName; } #endregion var query = await ( from x in db.DirNomens where x.Sub == docSecondHandRazbor2Tab.DirNomen2ID && x.DirNomenCategoryID == docSecondHandRazbor2Tab.DirNomenCategoryID select x ).ToListAsync(); if (query.Count() > 0) { docSecondHandRazbor2Tab.DirNomenID = query[0].DirNomenID; } else { Models.Sklad.Dir.DirNomen dirNomen = new Models.Sklad.Dir.DirNomen(); dirNomen.Sub = docSecondHandRazbor2Tab.DirNomen2ID; dirNomen.DirNomenTypeID = 1; dirNomen.DirNomenName = docSecondHandRazbor2Tab.DirNomenCategoryName; dirNomen.DirNomenCategoryID = docSecondHandRazbor2Tab.DirNomenCategoryID; dirNomen.DirNomenNameFull = docSecondHandRazbor2Tab.DirNomenCategoryName; db.Entry(dirNomen).State = EntityState.Added; await db.SaveChangesAsync(); docSecondHandRazbor2Tab.DirNomenID = dirNomen.DirNomenID; } #endregion #region 2. DocSecondHandRazbor2Tabs db.Entry(docSecondHandRazbor2Tab).State = entityState; await db.SaveChangesAsync(); #endregion #region 3. RemParties Models.Sklad.Doc.DocSecondHandPurch docSecondHandPurch = await db.DocSecondHandPurches.FindAsync(docSecondHandRazbor2Tab.DocSecondHandPurchID); Models.Sklad.Rem.RemParty remParty = new Models.Sklad.Rem.RemParty(); remParty.RemPartyID = null; remParty.DirNomenID = Convert.ToInt32(docSecondHandRazbor2Tab.DirNomenID); remParty.Quantity = docSecondHandRazbor2Tab.Quantity; remParty.Remnant = docSecondHandRazbor2Tab.Quantity; remParty.DirCurrencyID = docSecondHandRazbor2Tab.DirCurrencyID; //remParty.DirCurrencyMultiplicity = docSecondHandRazbor2Tab.DirCurrencyMultiplicity; //remParty.DirCurrencyRate = docSecondHandRazbor2Tab.DirCurrencyRate; remParty.DirVatValue = 0; // docPurch.DirVatValue; remParty.DirWarehouseID = docSecondHandPurch.DirWarehouseID; // docPurch.DirWarehouseID; remParty.DirWarehouseIDDebit = docSecondHandPurch.DirWarehouseID; // docPurch.DirWarehouseID; remParty.DirWarehouseIDPurch = Convert.ToInt32(docSecondHandPurch.DirWarehouseIDPurches); // docPurch.DirWarehouseID; remParty.DirContractorIDOrg = docSecondHandPurch.doc.DirContractorIDOrg; //!!! Важно !!! //if (docSecondHandRazbor2Tab.DirContractorID != null) remParty.DirContractorID = Convert.ToInt32(docSecondHandRazbor2Tab.DirContractorID); //else remParty.DirContractorID = docSecondHandPurch.DirContractorID; remParty.DirContractorID = docSecondHandPurch.doc.DirContractorIDOrg; //!!! Важно !!! //Дата Приёмки товара remParty.DocDatePurches = docSecondHandPurch.doc.DocDate; remParty.DirCharColourID = docSecondHandRazbor2Tab.DirCharColourID; remParty.DirCharMaterialID = docSecondHandRazbor2Tab.DirCharMaterialID; remParty.DirCharNameID = docSecondHandRazbor2Tab.DirCharNameID; remParty.DirCharSeasonID = docSecondHandRazbor2Tab.DirCharSeasonID; remParty.DirCharSexID = docSecondHandRazbor2Tab.DirCharSexID; remParty.DirCharSizeID = docSecondHandRazbor2Tab.DirCharSizeID; remParty.DirCharStyleID = docSecondHandRazbor2Tab.DirCharStyleID; remParty.DirCharTextureID = docSecondHandRazbor2Tab.DirCharTextureID; remParty.SerialNumber = docSecondHandRazbor2Tab.SerialNumber; remParty.Barcode = docSecondHandRazbor2Tab.Barcode; remParty.DocID = Convert.ToInt32(docSecondHandPurch.DocID); remParty.PriceCurrency = docSecondHandRazbor2Tab.PriceCurrency; remParty.PriceVAT = docSecondHandRazbor2Tab.PriceVAT; remParty.FieldID = Convert.ToInt32(docSecondHandRazbor2Tab.DocSecondHandRazbor2TabID); remParty.PriceRetailVAT = docSecondHandRazbor2Tab.PriceRetailVAT; remParty.PriceRetailCurrency = docSecondHandRazbor2Tab.PriceRetailCurrency; remParty.PriceWholesaleVAT = docSecondHandRazbor2Tab.PriceWholesaleVAT; remParty.PriceWholesaleCurrency = docSecondHandRazbor2Tab.PriceWholesaleCurrency; remParty.PriceIMVAT = docSecondHandRazbor2Tab.PriceIMVAT; remParty.PriceIMCurrency = docSecondHandRazbor2Tab.PriceIMCurrency; //DirNomenMinimumBalance remParty.DirNomenMinimumBalance = sysSetting.DirNomenMinimumBalance; remParty.DirEmployeeID = docSecondHandPurch.doc.DirEmployeeID; remParty.DocDate = docSecondHandPurch.doc.DocDate; db.Entry(remParty).State = EntityState.Added; await db.SaveChangesAsync(); #endregion #region 3. Лог: Пишем в Лог о смене статуса и мастера, если такое было logService.DocSecondHandPurchID = docSecondHandRazbor2Tab.DocSecondHandPurchID; logService.DirSecondHandLogTypeID = 6; //Смена статуса logService.DirEmployeeID = field.DirEmployeeID; //logService.DirSecondHandStatusID = DirSecondHandStatusID; logService.Msg = "Разборка: добавили запчасть: " + docSecondHandRazbor2Tab.dirNomen.DirNomenName; await logServicesController.mPutPostLogSecondHands(db, logService, EntityState.Added); #endregion return(docSecondHandRazbor2Tab); }
public async Task <IHttpActionResult> PutDocSecondHandRazbor2Tab(int id, DocSecondHandRazbor2Tab docSecondHandRazbor2Tab, HttpRequestMessage request) { return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg57(0)))); }