コード例 #1
0
        public async Task <IHttpActionResult> PostDocSecondHandPurch1Tab(DocSecondHandPurch1Tab docSecondHandPurch1Tab, HttpRequestMessage request)
        {
            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));

                //Права (1 - Write, 2 - Read, 3 - No Access)
                int iRight = await Task.Run(() => accessRight.Access(connectionString.Return(field.DirCustomersID, null, true), field.DirEmployeeID, "RightDocSecondHandPurch1Tabs"));

                if (iRight != 1)
                {
                    return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg57(0))));
                }

                //Разные Функции
                function.NumberDecimalSeparator();

                //Получам настройки
                Models.Sklad.Sys.SysSetting sysSetting = await db.SysSettings.FindAsync(1);

                #endregion

                #region Параметры

                var    paramList = request.GetQueryNameValuePairs();
                int    iDirSecondHandStatusID = Convert.ToInt32(paramList.FirstOrDefault(kv => string.Compare(kv.Key, "DirSecondHandStatusID", true) == 0).Value);
                string sDiagnosticRresults    = paramList.FirstOrDefault(kv => string.Compare(kv.Key, "sDiagnosticRresults", true) == 0).Value;

                //Получаем колекцию "Спецификации"
                Models.Sklad.Doc.DocSecondHandPurch1Tab[] DocSecondHandPurch1TabCollection = null;
                if (!String.IsNullOrEmpty(docSecondHandPurch1Tab.recordsDataX))
                {
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    DocSecondHandPurch1TabCollection = serializer.Deserialize <Models.Sklad.Doc.DocSecondHandPurch1Tab[]>("[" + docSecondHandPurch1Tab.recordsDataX + "]");
                }

                if (DocSecondHandPurch1TabCollection.Length > 0)
                {
                    docSecondHandPurch1Tab          = DocSecondHandPurch1TabCollection[0];
                    docSecondHandPurch1Tab.PriceVAT = docSecondHandPurch1Tab.PriceCurrency;
                    if (docSecondHandPurch1Tab.DirServiceJobNomenID == 0)
                    {
                        docSecondHandPurch1Tab.DirServiceJobNomenID = null;
                    }
                    if (docSecondHandPurch1Tab.DocSecondHandPurch1TabID == null || docSecondHandPurch1Tab.DocSecondHandPurch1TabID < 1)
                    {
                        docSecondHandPurch1Tab.DocSecondHandPurch1TabID = null;
                        docSecondHandPurch1Tab.DirEmployeeID            = field.DirEmployeeID;
                        docSecondHandPurch1Tab.DirCurrencyID            = sysSetting.DirCurrencyID;
                        docSecondHandPurch1Tab.DirCurrencyRate          = 1;
                        docSecondHandPurch1Tab.DirCurrencyMultiplicity  = 1;
                    }
                }

                #endregion


                #region Сохранение


                using (System.Data.Entity.DbContextTransaction ts = db.Database.BeginTransaction())
                {
                    db.Configuration.AutoDetectChangesEnabled = false;

                    try
                    {
                        #region Save docSecondHandPurch

                        Models.Sklad.Doc.DocSecondHandPurch docSecondHandPurch = await db.DocSecondHandPurches.FindAsync(docSecondHandPurch1Tab.DocSecondHandPurchID);

                        int?DirSecondHandStatusIDOLD = docSecondHandPurch.DirSecondHandStatusID;
                        docSecondHandPurch.DirSecondHandStatusID = iDirSecondHandStatusID;
                        db.Entry(docSecondHandPurch).State       = EntityState.Modified;


                        #region Лог - если поменялся статус

                        if (DirSecondHandStatusIDOLD != iDirSecondHandStatusID)
                        {
                            //Пишем в Лог о смене статуса и мастера, если такое было
                            logSecondHand.DocSecondHandPurchID   = docSecondHandPurch1Tab.DocSecondHandPurchID;
                            logSecondHand.DirSecondHandLogTypeID = 1;
                            logSecondHand.DirEmployeeID          = field.DirEmployeeID;
                            logSecondHand.DirSecondHandStatusID  = iDirSecondHandStatusID;
                            if (!String.IsNullOrEmpty(sDiagnosticRresults))
                            {
                                logSecondHand.Msg = sDiagnosticRresults;
                            }

                            await logSecondHandsController.mPutPostLogSecondHands(db, logSecondHand, EntityState.Added);
                        }

                        #endregion

                        #endregion


                        #region Save docSecondHandPurch1Tab


                        #region Лог

                        //Пишем в Лог о смене статуса и мастера, если такое было
                        logSecondHand.DocSecondHandPurchID   = docSecondHandPurch1Tab.DocSecondHandPurchID;
                        logSecondHand.DirSecondHandLogTypeID = 5;
                        logSecondHand.DirEmployeeID          = field.DirEmployeeID;
                        logSecondHand.DirSecondHandStatusID  = iDirSecondHandStatusID;

                        if (docSecondHandPurch1Tab.DocSecondHandPurch1TabID == null)
                        {
                            logSecondHand.Msg = "Создание записи " + docSecondHandPurch1Tab.DirServiceJobNomenName + " на сумму " + docSecondHandPurch1Tab.PriceCurrency;
                        }
                        else
                        {
                            logSecondHand.Msg = "Изменение записи " + docSecondHandPurch1Tab.DirServiceJobNomenName + " на сумму " + docSecondHandPurch1Tab.PriceCurrency;
                        }
                        if (!String.IsNullOrEmpty(sDiagnosticRresults))
                        {
                            logSecondHand.Msg += "<br /> Результат Диагностики: " + sDiagnosticRresults;
                        }

                        await logSecondHandsController.mPutPostLogSecondHands(db, logSecondHand, EntityState.Added);

                        #endregion

                        docSecondHandPurch1Tab.DirSecondHandStatusID = iDirSecondHandStatusID;

                        if (docSecondHandPurch1Tab.DocSecondHandPurch1TabID > 0)
                        {
                            db.Entry(docSecondHandPurch1Tab).State = EntityState.Modified;
                        }
                        else
                        {
                            docSecondHandPurch1Tab.DiagnosticRresults = sDiagnosticRresults;
                            docSecondHandPurch1Tab.TabDate            = DateTime.Now;

                            db.Entry(docSecondHandPurch1Tab).State = EntityState.Added;
                        }
                        await Task.Run(() => db.SaveChangesAsync());

                        #endregion


                        ts.Commit();
                    }
                    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))));
                    }
                }



                dynamic collectionWrapper = new
                {
                    DocSecondHandPurch1TabID = docSecondHandPurch1Tab.DocSecondHandPurch1TabID,
                    DirEmployeeID            = docSecondHandPurch1Tab.DirEmployeeID,
                    DirCurrencyID            = docSecondHandPurch1Tab.DirCurrencyID,
                    DirCurrencyRate          = docSecondHandPurch1Tab.DirCurrencyRate,
                    DirCurrencyMultiplicity  = docSecondHandPurch1Tab.DirCurrencyMultiplicity
                };
                return(Ok(returnServer.Return(true, collectionWrapper))); //return Ok(returnServer.Return(true, ""));

                #endregion
            }
            catch (Exception ex)
            {
                return(Ok(returnServer.Return(false, exceptionEntry.Return(ex))));
            }
        }
コード例 #2
0
        public async Task <IHttpActionResult> DeleteDocSecondHandPurch1Tab(int id, HttpRequestMessage request)
        {
            #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));

            //Права (1 - Write, 2 - Read, 3 - No Access)
            int iRight = await Task.Run(() => accessRight.Access(connectionString.Return(field.DirCustomersID, null, true), field.DirEmployeeID, "RightDocSecondHandPurch1Tabs"));

            if (iRight != 1)
            {
                return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg57(0))));
            }

            //Разные Функции
            function.NumberDecimalSeparator();

            //Получам настройки
            Models.Sklad.Sys.SysSetting sysSetting = await db.SysSettings.FindAsync(1);

            #endregion

            #region Параметры

            var    paramList = request.GetQueryNameValuePairs();
            int    iDirSecondHandStatusID = Convert.ToInt32(paramList.FirstOrDefault(kv => string.Compare(kv.Key, "DirSecondHandStatusID", true) == 0).Value);
            string sDiagnosticRresults    = paramList.FirstOrDefault(kv => string.Compare(kv.Key, "sDiagnosticRresults", true) == 0).Value;

            #endregion


            #region Удаление

            try
            {
                DocSecondHandPurch1Tab docSecondHandPurch1Tab = await db.DocSecondHandPurch1Tabs.FindAsync(id);

                if (docSecondHandPurch1Tab == null)
                {
                    //return Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg99));

                    dynamic collectionWrapper2 = new
                    {
                        ID  = 0,
                        Msg = Classes.Language.Sklad.Language.msg99
                    };
                    return(Ok(returnServer.Return(true, collectionWrapper2)));
                }


                using (System.Data.Entity.DbContextTransaction ts = db.Database.BeginTransaction())
                {
                    db.Configuration.AutoDetectChangesEnabled = false;

                    try
                    {
                        #region Лог

                        //Пишем в Лог о смене статуса и мастера, если такое было
                        logSecondHand.DocSecondHandPurchID   = docSecondHandPurch1Tab.DocSecondHandPurchID;
                        logSecondHand.DirSecondHandLogTypeID = 5;
                        logSecondHand.DirEmployeeID          = field.DirEmployeeID;
                        logSecondHand.DirSecondHandStatusID  = null;
                        logSecondHand.Msg  = "Удаление записи " + docSecondHandPurch1Tab.DirServiceJobNomenName + " на сумму " + docSecondHandPurch1Tab.PriceCurrency;
                        logSecondHand.Msg += "<br />Причина удаление: " + sDiagnosticRresults;

                        await logSecondHandsController.mPutPostLogSecondHands(db, logSecondHand, EntityState.Added);

                        #endregion

                        #region Save

                        db.DocSecondHandPurch1Tabs.Remove(docSecondHandPurch1Tab);
                        await db.SaveChangesAsync();

                        #endregion

                        ts.Commit();
                    }
                    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))));
                    }
                }


                dynamic collectionWrapper = new
                {
                    ID  = docSecondHandPurch1Tab.DocSecondHandPurch1TabID,
                    Msg = Classes.Language.Sklad.Language.msg19
                };
                return(Ok(returnServer.Return(true, collectionWrapper))); //return Ok(returnServer.Return(true, "")
            }
            catch (Exception ex)
            {
                return(Ok(returnServer.Return(false, exceptionEntry.Return(ex))));
            }

            #endregion
        }
コード例 #3
0
 public async Task <IHttpActionResult> PutDocSecondHandPurch1Tab(int id, DocSecondHandPurch1Tab docSecondHandPurch1Tab)
 {
     return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg57(0))));
 }