Esempio n. 1
0
 private void Confirmed_Active_True(DbConnectionLogin con, int DirCustomersID)
 {
     //Получаем данные клиента.
     Models.Login.Dir.DirCustomer dirCustomer = con.DirCustomers.Where(x => x.DirCustomersID == DirCustomersID).ToList()[0];
     dirCustomer.Confirmed = true;
     dirCustomer.Active    = true;
     //Меняем: Подтверждён и Активен
     con.Entry(dirCustomer).State = EntityState.Modified;
     con.SaveChanges();
 }
Esempio n. 2
0
        public async Task <IHttpActionResult> PostDirWebShopUO(DirWebShopUO dirWebShopUO)
        {
            #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, "RightDirWebShopUOs"));

            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 Проверки

            if (!ModelState.IsValid)
            {
                return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg91)));                     //return BadRequest(ModelState);
            }
            if (!dirWebShopUO.Nomen_Remains == null)
            {
                dirWebShopUO.Nomen_Remains = false;
            }
            if (!dirWebShopUO.Orders_Reserve == null)
            {
                dirWebShopUO.Orders_Reserve = false;
            }


            //Подстановки - некоторые поля надо заполнить, если они не заполены
            //dirWebShopUO.Substitute();

            #endregion


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

            try
            {
                db.Entry(dirWebShopUO).State = EntityState.Added;
                await Task.Run(() => db.SaveChangesAsync());


                //Сохраняем Доменное имя в МС Скул
                using (DbConnectionLogin con = new DbConnectionLogin("ConnStrMSSQL"))
                {
                    Models.Login.Dir.DirCustomer dirCustomer = await db.DirCustomers.FindAsync(field.DirCustomersID);

                    dirCustomer.DomainName       = dirWebShopUO.DomainName;
                    con.Entry(dirCustomer).State = EntityState.Modified;
                    con.SaveChanges();
                }


                #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       = dirWebShopUO.DirWebShopUOID;
                sysJourDisp.Description        = "";
                try { sysJourDispsController.mPutPostSysJourDisps(db, sysJourDisp, EntityState.Added); } catch (Exception ex) { }

                #endregion


                dynamic collectionWrapper = new
                {
                    ID = dirWebShopUO.DirWebShopUOID
                };
                return(Ok(returnServer.Return(true, collectionWrapper))); //return Ok(returnServer.Return(true, ""));
            }
            catch (Exception ex)
            {
                return(Ok(returnServer.Return(false, exceptionEntry.Return(ex))));
            }

            #endregion
        }
Esempio n. 3
0
        private bool mRegistration(Models.Login.Dir.DirCustomerReg dirCustomerReg, int iLanguage)
        {
            //Для записи в БД, т.к. использовать "dirCustomerReg" нельзя!
            Models.Login.Dir.DirCustomer dirCustomer = new Models.Login.Dir.DirCustomer();

            if (dirCustomerReg != null && ModelState.IsValid)
            {
                try
                {
                    using (DbConnectionLogin con = new DbConnectionLogin("ConnStrMSSQL"))
                    {
                        #region Проверка
                        // на существования такого логина
                        int iCount =
                            (
                                (
                                    from dirCustomers in con.DirCustomers
                                    where dirCustomers.Login == dirCustomerReg.Login
                                    select dirCustomers.Login
                                ).Concat
                                (
                                    from dirLoginNot in con.DirLoginNot
                                    where dirLoginNot.Login == dirCustomerReg.Login
                                    select dirLoginNot.Login
                                )
                            ).Count();

                        if (iCount > 0)
                        {
                            con.Database.Connection.Close(); ViewData["Msg"] = Classes.Language.Login.Language.msg1(iLanguage); return(false);
                        }

                        // на существования такого реферала
                        if (dirCustomerReg.Refer != 0)
                        {
                            int iCountRefer =
                                (
                                    from DirCustomers in con.DirCustomers
                                    where dirCustomerReg.DirCustomersID == dirCustomerReg.Refer
                                    select dirCustomerReg.Login
                                ).Count();
                            if (iCountRefer == 0)
                            {
                                dirCustomerReg.Refer = 0;
                            }
                        }
                        #endregion

                        #region Сохраняем
                        //Формирование пароля
                        Classes.Function.FunctionMSSQL.RandomSymbol randomSymbol = new Classes.Function.FunctionMSSQL.RandomSymbol();
                        dirCustomerReg.Pswd = randomSymbol.ReturnRandom(10);

                        //Переносим данные в "нужную" модель: dirCustomerReg => dirCustomer
                        dirCustomer.DirCustomersDate = DateTime.Now;
                        dirCustomer.Email            = dirCustomerReg.Email;
                        dirCustomer.Login            = dirCustomerReg.Login;
                        dirCustomer.DomainName       = dirCustomerReg.Login;
                        dirCustomer.Pswd             = dirCustomerReg.Pswd;
                        dirCustomer.Telefon          = dirCustomerReg.Telefon;
                        dirCustomer.FIO           = dirCustomerReg.FIO;
                        dirCustomer.DirLanguageID = dirCustomerReg.DirLanguageID;
                        dirCustomer.DirCountryID  = dirCustomerReg.DirCountryID;
                        dirCustomer.Refer         = dirCustomerReg.Refer;
                        dirCustomer.SendMail      = false;
                        dirCustomer.Active        = false;
                        dirCustomer.Pay           = true;
                        dirCustomer.Confirmed     = false;

                        con.Entry(dirCustomer).State = EntityState.Added;
                        try
                        {
                            con.SaveChanges();
                        }
                        catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                        {
                            System.Text.StringBuilder sb = new System.Text.StringBuilder();

                            foreach (var failure in ex.EntityValidationErrors)
                            {
                                //sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());
                                foreach (var error in failure.ValidationErrors)
                                {
                                    sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                                    sb.AppendLine();
                                }
                            }

                            throw new System.Data.Entity.Validation.DbEntityValidationException(
                                      //"Entity Validation Failed - errors follow:\n" +
                                      sb.ToString(), ex
                                      ); // Add the original exception as the innerException
                        }

                        /*catch (Exception ex)
                         * {
                         *  throw new System.InvalidOperationException(ex.Message);
                         * }*/

                        #endregion
                    }

                    #region Отправка письма на E-Mail
                    try
                    {
                        //Текс на русском
                        string sSendTest = Classes.Language.Login.Language.txtRegistrationMail(dirCustomer, iLanguage);
                        Classes.Function.FunctionMSSQL.FunMailSend funMailSend = new Classes.Function.FunctionMSSQL.FunMailSend();
                        //Отправка клиенту
                        funMailSend.SendTo_OtherEMail(Classes.Language.Login.Language.msg2(iLanguage), sSendTest, dirCustomer.Email);
                        //Отправка себе
                        try { funMailSend.SendTo_ESklad24(Classes.Language.Login.Language.msg2(iLanguage), "E-Mail: " + dirCustomer.Email + ", Login: "******"<br />" + Classes.Language.Login.Language.msg2(iLanguage) + "<hr />" + sSendTest); } catch { }
                    }
                    catch (Exception ex)
                    {
                        ViewData["Msg"]   = Classes.Language.Login.Language.msg4(iLanguage) + ex.Message + "";
                        ViewData["Title"] = Classes.Language.Login.Language.msg5(iLanguage);
                        return(true);
                    }
                    #endregion

                    using (DbConnectionLogin con = new DbConnectionLogin("ConnStrMSSQL"))
                    {
                        #region Пишем в БД, что Мейл отправлен (SendMail=true)
                        dirCustomer.SendMail         = true;
                        con.Entry(dirCustomer).State = EntityState.Modified;
                        con.SaveChanges();
                        #endregion
                    }
                }
                catch (Exception ex)
                {
                    string sMsg = exceptionEntry.Return(ex);
                    ViewData["Msg"] = Classes.Language.Login.Language.error(iLanguage) + ": <br />" + sMsg + "<br /> " + Classes.Language.Login.Language.msg6(iLanguage) + ": <a href='mailto:[email protected]' rel='nofollow'>[email protected]</a>"; return(false);
                }


                ViewData["Title"] = Classes.Language.Login.Language.msg5(iLanguage);
                ViewData["Msg"]   = Classes.Language.Login.Language.msg7(iLanguage);
                return(true);
            }
            else
            {
                return(false);
            }
        }