Exemple #1
0
        private int getCompanyIdByUser(ApplicationUser user)
        {
            UserInCompany company = context.UserInCompany.Where(u => u.User.Id.Equals(user.Id)).FirstOrDefault();

            if (company == null)
            {
                return(0);
            }
            return(company.CompanyId);
        }
Exemple #2
0
 public void UpdateUserData(ApplicationUser user, string currentUserId)
 {
     if (!user.Id.Equals(currentUserId))
     {
         int companyId = getCompanyIdByUser(user);
         if (companyId == 0)
         {
             ApplicationUser currentUser = GetUserById(currentUserId);
             companyId = getCompanyIdByUser(currentUser);
             UserInCompany uic = new UserInCompany();
             uic.CompanyId            = companyId;
             uic.UserId               = user.Id;
             uic.CreateTime           = DateTime.Now;
             uic.ModyfiTime           = DateTime.Now;
             context.Entry(uic).State = EntityState.Added;
         }
     }
     context.Entry(user).State = EntityState.Modified;
     context.SaveChanges();
 }
Exemple #3
0
        public void UpdateCompany(CompanyViewModel model, string userId)
        {
            Company company = (from c in context.Company join u in context.UserInCompany on c.CompanyID equals u.CompanyId where u.UserId.Equals(userId) select c).FirstOrDefault();

            if (company != null && company.CompanyID != 0)
            {
                model.IsSetCompany = true;
            }
            else
            {
                model.IsSetCompany = false;
            }
            if (model.IsSetCompany)
            {
                company.City                 = model.City;
                company.CompanyName          = model.CompanyName;
                company.FlatNumber           = model.FlatNumber;
                company.HouseNumber          = model.HouseNumber;
                company.NIP                  = model.NIP;
                company.Street               = model.Street;
                company.ZipCode              = model.ZipCode;
                company.CreateTime           = DateTime.Now;
                company.ModyfiTime           = DateTime.Now;
                context.Entry(company).State = System.Data.Entity.EntityState.Modified;
            }
            else
            {
                addCompany(model, ref company);
                UserInCompany uic = new UserInCompany();
                uic.CompanyId            = company.CompanyID;
                uic.UserId               = userId;
                uic.CreateTime           = DateTime.Now;
                uic.ModyfiTime           = DateTime.Now;
                context.Entry(uic).State = System.Data.Entity.EntityState.Added;
            }
            context.SaveChanges();
        }