Exemple #1
0
 private void Add_Click(object sender, EventArgs e)
 {
     try
     {
         Goods newGoods = new Goods
         {
             title             = title.Text,
             id_goods_category = (int)categoryBox.SelectedValue,
             id_subsidiary_companies_region = (int)(new ConfigJson()).SubsidiaryCompaniesRegion(),
             shelf_life   = Convert.ToInt32(shelf_life.Text),
             date_create  = date_create.Value,
             date_end     = date_create.Value.AddDays(Convert.ToInt32(shelf_life.Text)),
             price        = (price.Text != "") ? Convert.ToDecimal(price.Text) : 0,
             discont      = (discont.Text != "") ? Convert.ToDouble(discont.Text) : 0,
             measurement  = measurement.Text,
             description  = description.Text,
             count        = (count.Text != "") ? Convert.ToInt32(count.Text) : 0,
             code         = code.Text,
             manufacturer = manufacturer.Text,
             status       = status.Text
         };
         db.Goods.Add(newGoods);
         db.SaveChanges();
     }
     catch
     {
         MessageBox.Show("Не все поля заполнены");
     }
     RefreshModels();
 }
Exemple #2
0
        public JsonResult DeleteCv(int id)
        {
            var removable = db.Cv.FirstOrDefault(x => x.Id == id);

            db.Cv.Remove(removable ?? throw new InvalidOperationException());
            db.SaveChanges();
            return(Json(new
            {
                success = true,
                text = "OK"
            }));
        }
Exemple #3
0
        private void Add_Click(object sender, EventArgs e)
        {
            int?id_region = db.Subsidiary_companies_region.Find((int)new ConfigJson().SubsidiaryCompaniesRegion()).id_subsidiary_companies.Value;

            Goods_category newCat = new Goods_category
            {
                title   = titleCategory.Text,
                date_up = DateTime.Now,
                subsidiary_companies_id = db.Subsidiary_companies.Where(s => s.id == id_region).First().id
            };

            db.Goods_category.Add(newCat);
            db.SaveChanges();
            RefreshModels();
            titleCategory.Clear();
        }
Exemple #4
0
        private void saleBasket()
        {
            Sale sale = new Sale()
            {
                id_employess = this.user.id,
                discont      = Convert.ToDecimal(discont_all.Text),
                price        = Convert.ToDecimal(price_all.Text),
                payment      = Convert.ToDecimal(payment.Text),
                id_subsidiary_companies_region = (int)(new ConfigJson()).SubsidiaryCompaniesRegion(),
                date_up = DateTime.Now
            };

            db.Sale.Add(sale);
            foreach (DataGridViewRow row in gridSeller.Rows)
            {
                int?id          = Convert.ToInt32(row.Cells["id"].Value);
                var goodsBasket = db.Goods.FirstOrDefault(g => g.id == id);
                if (goodsBasket.count-- == 0)
                {
                    goodsBasket.basket = "продано";
                }
                Sale_basket sale_basket = new Sale_basket()
                {
                    id_goods = goodsBasket.id,
                    id_sale  = sale.id,
                    subsidiary_companies_region = new ConfigJson().SubsidiaryCompaniesRegion()
                };
                db.Sale_basket.Add(sale_basket);
            }
            db.SaveChanges();
        }
Exemple #5
0
        public IActionResult GetNewUser()
        {
            User newUser;

            using (var ctx = new ConnectContext())
            {
                var address = ctx.Set <Address>().Find(1);

                var id = new Random().Next(10, 4000);

                newUser = new User()
                {
                    Id        = id,
                    Name      = $"user{id}",
                    AddressId = address.Id
                };

                ctx.Set <User>().Add(newUser);
                ctx.SaveChanges();

                Console.WriteLine(newUser.Address == null);
            }

            //this will be false as newUser's Address property got automatically populated
            return(Ok(newUser.Address == null));
        }
Exemple #6
0
        private static void AddLicenseForUser(ConnectContext context, ConnectUser user, RegisterUserViewModel data)
        {
            var licenseUser = context.Clients.Include(x => x.Licenses).FirstOrDefault(c => c.Name == user.CompanyKey);

            if (licenseUser == null)
            {
                licenseUser = new Client
                {
                    Name     = user.CompanyKey,
                    Created  = DateTime.Now,
                    AccessId = Guid.NewGuid(),
                    Licenses = new List <License>()
                };
                context.Clients.Add(licenseUser);
            }

            licenseUser.Licenses.Add(new License
            {
                Created    = DateTime.Now,
                Expiration = data.Expiration,
                Key        = data.Expiration.Ticks.ToString(CultureInfo.InvariantCulture).TrimEnd(char.Parse("0")),
                AccessId   = Guid.NewGuid()
            });

            context.SaveChanges();
        }
Exemple #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.educationItem != null)
                {
                    this.educationItem.type          = type.Text;
                    this.educationItem.organization  = organization.Text;
                    this.educationItem.date_create   = date_create.Value;
                    this.educationItem.number        = Convert.ToInt32(number.Text);
                    this.educationItem.qualification = qualification.Text;
                    this.educationItem.specialty     = specialty.Text;
                    this.educationItem.date_up       = DateTime.Now;
                    db.SaveChanges();
                }
                else
                {
                    Employees_education education = new Employees_education
                    {
                        id_employees  = this.id_employees,
                        type          = type.Text,
                        organization  = organization.Text,
                        date_create   = date_create.Value,
                        number        = Convert.ToInt32(number.Text),
                        qualification = qualification.Text,
                        specialty     = specialty.Text,
                        date_up       = DateTime.Now,
                        subsidiary_companies_region_id = new ConfigJson().SubsidiaryCompaniesRegion()
                    };
                    db.Employees_education.Add(education);
                    db.SaveChanges();
                    this.education.DataSource = db.Employees_education.Where(x => x.id_employees == id_employees).ToList();

                    this.education.Refresh();
                }
            }
            catch
            {
                MessageBox.Show("Заполните поля");
            }
            finally
            {
                this.Close();
            }
        }
Exemple #8
0
 private void delete_Click(object sender, EventArgs e)
 {
     if (gridSaleBasket.CurrentRow != null)
     {
         var goodsRow = gridSaleBasket.CurrentRow.DataBoundItem as Goods;
         db.Goods.Remove(goodsRow);
     }
     db.SaveChanges();
     RefreshModels();
 }
Exemple #9
0
        static void Main(string[] args)
        {
            ConnectContext context = new ConnectContext();
            StoreDTO       store   = new StoreDTO();

            store.productName   = "Table";
            store.quantity      = 2;
            store.lastPurchased = Convert.ToDateTime("10-10-2020");
            context.StoreDTO.Add(store);
            context.SaveChanges();
        }
Exemple #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime?_date_end      = null;
                int?     id_user_access = null;

                if (!not.Checked)
                {
                    _date_end = date_end.Value;
                }
                if (userAccess.Text != "")
                {
                    id_user_access = (int)userAccess.SelectedValue;
                }
                Employees addEmp = new Employees
                {
                    first_name     = first_name.Text,
                    middle_name    = middle_name.Text,
                    last_name      = last_name.Text,
                    birthday       = birthday.Value,
                    id_user_access = id_user_access,
                    position       = position.Text,
                    expiriens      = expiriens.Text,
                    date_begin     = date_begin.Value,
                    date_end       = _date_end,
                    id_subsidiary_companies_region = (int)subsidiary_companies_region.SelectedValue,
                    date_up = DateTime.Now
                };
                db.Employees.Add(addEmp);
                db.SaveChanges();
                refreshModel();
            }

            catch
            {
                MessageBox.Show("Заполните поля");
            }
        }
Exemple #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                User_access addAccess = new User_access
                {
                    login    = login.Text,
                    password = password.Text,
                    type     = type.Text,
                    status   = status.Text,
                    id_subsidiary_companies_region = (int)subsidiary_companies_region.SelectedValue,
                    date_up = DateTime.Now
                };
                db.User_access.Add(addAccess);
                db.SaveChanges();
                refreshModel();
            }

            catch
            {
                MessageBox.Show("Заполните поля");
            }
        }
Exemple #12
0
        private void AssociateUserWithTachoCentre(ConnectContext context, ConnectUser user)
        {
            var userId = User.Identity.GetUserId <int>();
            var tachographCentreUser = context.Users.First(c => c.Id == userId);
            var operatorUser         = context.Users.First(c => c.Id == user.Id);

            var existingLink = context.TachoCentreOperators.Include(c => c.OperatorUser)
                               .Include(c => c.TachographCentreUser)
                               .Any(c => c.TachographCentreUser.Id == tachographCentreUser.Id && c.OperatorUser.Id == operatorUser.Id);

            if (!existingLink)
            {
                context.TachoCentreOperators.Add(new TachoCentreOperator
                {
                    OperatorUser         = operatorUser,
                    TachographCentreUser = tachographCentreUser
                });

                context.SaveChanges();
            }
        }
Exemple #13
0
        public IHttpActionResult Post([FromBody] RegisterUserViewModel data) //Do not make async until upgrading to 4.5.1
        {
            using (var context = new ConnectContext())
            {
                var user = new ConnectUser();
                user.UserName        = user.Email = data.EmailAddress;
                user.CompanyKey      = data.CompanyName;
                user.IsAuthorized    = true;
                user.LicenseKey      = Convert.ToInt32(data.Expiration.Ticks.ToString(CultureInfo.InvariantCulture).TrimEnd(char.Parse("0")));
                user.CustomerContact = new CustomerContact();

                var company = context.Users.FirstOrDefault(c => c.CompanyKey == user.CompanyKey);
                if (company != null)
                {
                    return(BadRequest("The company name is already in use."));
                }

                using (var transaction = new TransactionScope())
                {
                    var result = UserManager.Create(user, data.Password);
                    if (result.Succeeded)
                    {
                        UserManager.AddToRole(user.Id, ConnectRoles.TachographCentre);
                        context.SaveChanges();

                        SendConfirmationEmail(user);
                        AssociateUserWithTachoCentre(context, user);
                        AddLicenseForUser(context, user, data);

                        transaction.Complete();
                        return(Ok());
                    }
                    return(BadRequest(string.Join(",", result.Errors)));
                }
            }
        }