コード例 #1
0
        public async Task<Company> GetCompany(Company company)
        {
            var filter2 = Builders<BsonDocument>.Filter.Eq("_id", ObjectId.Parse(company.Id));
            var companyBson = await _companyCollection.Find(filter2).ToListAsync().ConfigureAwait(false);
            
            if (companyBson.Count > 0)
            {
                company.Id = Constants.IdRegex.Match(companyBson[0].ElementAt(0).Value.RawValue.ToJson()).Value.Substring(1);
                company.Name = companyBson[0].ElementAt(1).Value.AsString;
                company.Country = companyBson[0].ElementAt(2).Value.AsString;
                company.Phone = companyBson[0].ElementAt(3).Value.AsString;
                company.Address1 = companyBson[0].ElementAt(4).Value.AsString;
                company.Address2 = null;
                company.City = companyBson[0].ElementAt(6).Value.AsString;
                company.Contact = companyBson[0].ElementAt(7).Value.AsString;
                company.Email = companyBson[0].ElementAt(8).Value.AsString;
                try
                {
                    company.LogoBytes = companyBson[0].ElementAt(9).Value.AsByteArray;
                }
                catch (InvalidCastException ice)
                {
                    //don't assign
                }
            }

            return company;
        }
コード例 #2
0
        public async Task<Company> UpdateCompany(Company company)
        {
            var filter = Builders<BsonDocument>.Filter.Eq("_id", ObjectId.Parse(company.Id));
            if (company.Logo != null)
            {
                MemoryStream target = new MemoryStream();
                company.Logo.InputStream.CopyTo(target);
                company.LogoBytes = target.ToArray();
            }

            var update = Builders<BsonDocument>.Update;
            var updateList = new List<UpdateDefinition<BsonDocument>>();
            foreach (PropertyInfo prop in typeof(Company).GetProperties())
            {
                if ((prop.GetValue(company) != null && prop.Name != "Logo"))
                {
                    if(prop.Name == "LogoBytes")
                        updateList.Add(update.Set("logo", prop.GetValue(company) as byte[]));
                    else updateList.Add(update.Set(prop.Name.ToLower(), prop.GetValue(company)));
                }
            }

            await _companyCollection.UpdateOneAsync(filter, update.Combine(updateList)).ConfigureAwait(false);

            return company;
        }
コード例 #3
0
 public Company UpdateCompany(Company company)
 {
     var updatedCompany = _companyDao.UpdateCompany(company);
     updatedCompany.Wait();
     HttpContext.Current.Session["currentcompany"] = company;
     return company;
 }
コード例 #4
0
        public Company GetCompany(Company company)
        {
            var companyResult = _companyDao.GetCompany(company);
            companyResult.Wait();
            company = companyResult.Result;

            HttpContext.Current.Session["currentcompany"] = company;
            return company;
        }
コード例 #5
0
        public bool ValidateUser(User user)
        {
            user.Role = null;
            var result = _userDao.GetUsersAsync(user);

            result.Wait();

            if (result.Result.IsValid)
            {
                user = result.Result.Users.First();
                HttpContext.Current.Session["role"] = Enum.GetName(typeof (Role), user.Role);
                HttpContext.Current.Session["currentuser"] = user;

                var company = new Company() {Id = user.Company};
                company = _companyBizManager.GetCompany(company);
                HttpContext.Current.Session["currentcompany"] = company;
            }
            return result.Result.IsValid;
        }
コード例 #6
0
 public ActionResult UpdateCompany(Company org)
 {
     _companyBizManager.UpdateCompany(org);
     return RedirectToAction("Company");
 }