public CompanyPartner GetCompanyPartnerByNameOrInsert(string _name)
        {
            try
            {
                using (var context = new VeraEntities())
                {
                    var CompanyPartner = context.CompanyPartner.FirstOrDefault(x => x.Name.Trim() == _name.Trim() && x.Status > 0);

                    if (CompanyPartner == null)
                    {
                        CompanyPartner = new CompanyPartner()
                        {
                            Name   = _name.Trim(),
                            Status = 1
                        };

                        context.CompanyPartner.Add(CompanyPartner);
                        context.SaveChanges();
                        return(CompanyPartner);
                    }

                    return(CompanyPartner);
                }
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
        public ActionResult DeletePartner(IEnumerable <PartnersViewModel> models)
        {
            var datasource = new DataSource <PartnersViewModel>();

            if (ModelState.IsValid)
            {
                foreach (PartnersViewModel model in models)
                {
                    var partner = new CompanyPartner
                    {
                        Id        = model.Id,
                        AddressId = model.AddressId
                    };

                    _hrUnitOfWork.CompanyRepository.Remove(partner);
                }

                datasource.Errors = SaveChanges(Language);
                datasource.Total  = models.Count();
            }

            datasource.Data = models;

            if (datasource.Errors.Count() > 0)
            {
                return(Json(datasource));
            }
            else
            {
                return(Json(datasource.Data));
            }
        }
        public CompanyPartner InsertPartner(CompanyPartner partner)
        {
            using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew))
            {
                try
                {
                    StandartPersistence standartPersistence =
                        new StandartPersistence(this.Connection);

                    if (partner != null)
                    {
                        partner.Password    = CryptHelper.Encrypt(partner.Password);
                        partner.DateCreated = DateTime.Now;
                        partner.DateUpdated = DateTime.Now;
                        standartPersistence.Insert(partner);
                    }

                    transactionScope.Complete();
                    partner.Password = CryptHelper.Decrypt(partner.Password);
                    return(partner);
                }
                catch (SqlException e)
                {
                    throw e;
                }
                catch (TransactionException e)
                {
                    throw e;
                }
            }
        }
 public void Remove(CompanyPartner partner)
 {
     if (Context.Entry(partner).State == EntityState.Detached)
     {
         context.CompanyPartners.Attach(partner);
     }
     context.CompanyPartners.Remove(partner);
 }
        public ActionResult UpdatePartner(IEnumerable <PartnersViewModel> models, IEnumerable <OptionsViewModel> options)
        {
            var datasource = new DataSource <PartnersViewModel>();

            datasource.Data  = models;
            datasource.Total = models.Count();

            if (ModelState.IsValid)
            {
                if (ServerValidationEnabled)
                {
                    var errors = _hrUnitOfWork.CompanyRepository.Check(new CheckParm
                    {
                        CompanyId    = CompanyId,
                        ObjectName   = "CompanyPartners",
                        Columns      = Models.Utils.GetModifiedRows(ModelState.Where(a => a.Key.Contains("models"))),
                        ParentColumn = "CompanyId",
                        Culture      = Language
                    });

                    if (errors.Count() > 0)
                    {
                        datasource.Errors = errors;
                        return(Json(datasource));
                    }
                }

                for (var i = 0; i < models.Count(); i++)
                {
                    var partner = new CompanyPartner();
                    AutoMapper(new AutoMapperParm()
                    {
                        ObjectName = "CompanyPartners", Destination = partner, Source = models.ElementAtOrDefault(i), Version = 0, Options = options.ElementAtOrDefault(i)
                    });
                    partner.ModifiedTime = DateTime.Now;
                    partner.ModifiedUser = UserName;


                    _hrUnitOfWork.CompanyRepository.Attach(partner);
                    _hrUnitOfWork.CompanyRepository.Entry(partner).State = EntityState.Modified;
                }

                datasource.Errors = SaveChanges(Language);
            }
            else
            {
                datasource.Errors = Models.Utils.ParseErrors(ModelState.Values);
            }

            if (datasource.Errors.Count() > 0)
            {
                return(Json(datasource));
            }
            else
            {
                return(Json(datasource.Data));
            }
        }
Exemple #6
0
 public ActionResult <ObjectResult> InsertPartner([FromBody] CompanyPartner partner)
 {
     try
     {
         CompanyService companyService = new CompanyService(Startup.BeePlaceDataBaseConnectionString);
         companyService.InsertPartner(partner);
         return(StatusCode((int)HttpStatusCode.OK, partner));
     }
     catch (Exception e)
     {
         return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
     }
 }
 private void UpdateObject(CompanyPartner _newCompanyPartner, ref CompanyPartner _oldCompanyPartner)
 {
     try
     {
         foreach (PropertyInfo CompanyPartnerPropInfo in _newCompanyPartner.GetType().GetProperties().ToList())
         {
             _oldCompanyPartner.GetType().GetProperty(CompanyPartnerPropInfo.Name).SetValue(_oldCompanyPartner, _newCompanyPartner.GetType().GetProperty(CompanyPartnerPropInfo.Name).GetValue(_newCompanyPartner));
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
 public CompanyPartner AddNewCompanyPartner(CompanyPartner _CompanyPartner)
 {
     try
     {
         using (var context = new VeraEntities())
         {
             context.CompanyPartner.Add(_CompanyPartner);
             int numOfInserted = context.SaveChanges();
             return(numOfInserted > 0 ? _CompanyPartner : null);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemple #9
0
 public ActionResult <ObjectResult> UpdateCredentials([FromBody] CompanyCredentials credentials)
 {
     try
     {
         CompanyService companyService = new CompanyService(Startup.BeePlaceDataBaseConnectionString);
         var            partner        = new CompanyPartner();
         partner.Email    = credentials.Email;
         partner.Password = credentials.Password;
         companyService.UpdateCompanyPartnerCredentials(partner);
         return(StatusCode((int)HttpStatusCode.OK, credentials));
     }
     catch (Exception e)
     {
         return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
     }
 }
Exemple #10
0
        public void UpdateCompanyPartnerCredentials(CompanyPartner companyPartner)
        {
            try
            {
                StandartPersistence standartPersistence =
                    new StandartPersistence(this.Connection);

                companyPartner.Password = CryptHelper.Encrypt(companyPartner.Password);

                standartPersistence.Execute(CommandType.Text,
                                            "UPDATE CompanyPartner SET Email = @Email, [Password] = @Password WHERE Email = @Email AND [Password] = @Password",
                                            new { companyPartner.Email, companyPartner.Password });
            }
            catch (SqlException e)
            {
                throw e;
            }
        }
Exemple #11
0
        public ActionResult <ObjectResult> Login([FromBody] CompanyPartner companyPartner)
        {
            try
            {
                CompanyService companyService = new CompanyService(Startup.BeePlaceDataBaseConnectionString);
                Model.Profile.Company.Entity.Company company = new Model.Profile.Company.Entity.Company();
                company = companyService.LoginCompany(companyPartner);

                if (company.CompanyPartners != null && company.CompanyPartners.Count > 0)
                {
                    return(StatusCode((int)HttpStatusCode.OK, company));
                }
                else
                {
                    return(StatusCode((int)HttpStatusCode.Unauthorized));
                }
            }
            catch (Exception e)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
            }
        }
        public CompanyPartner UpdateCompanyPartner(CompanyPartner _CompanyPartner)
        {
            try
            {
                using (var context = new VeraEntities())
                {
                    var oldCompanyPartner = context.CompanyPartner.FirstOrDefault(u => u.Id == _CompanyPartner.Id);
                    if (oldCompanyPartner != null)
                    {
                        UpdateObject(_CompanyPartner, ref oldCompanyPartner);
                        var numberOfUpdatedCompanyPartner = context.SaveChanges();
                        return(numberOfUpdatedCompanyPartner > 0 ? _CompanyPartner : null);
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public ActionResult CreatePartner(IEnumerable <PartnersViewModel> models)
        {
            var result     = new List <CompanyPartner>();
            var datasource = new DataSource <PartnersViewModel>();

            datasource.Data  = models;
            datasource.Total = models.Count();

            if (ModelState.IsValid)
            {
                if (ServerValidationEnabled)
                {
                    var errors = _hrUnitOfWork.CompanyRepository.Check(new CheckParm
                    {
                        CompanyId    = CompanyId,
                        ObjectName   = "CompanyPartners",
                        Columns      = Models.Utils.GetModifiedRows(ModelState),
                        ParentColumn = "CompanyId",
                        Culture      = Language
                    });
                    if (errors.Count() > 0)
                    {
                        datasource.Errors = errors;
                        return(Json(datasource));
                    }
                }

                //  Iterate all updated products which are posted by the Kendo PageDiv
                foreach (PartnersViewModel model in models)
                {
                    // Create a new branch entity and set its properties from branchViewModel
                    var partner = new CompanyPartner
                    {
                        Name        = model.Name,
                        Email       = model.Email,
                        Telephone   = model.Telephone,
                        CompanyId   = model.CompanyId,
                        AddressId   = model.AddressId,
                        Mobile      = model.Mobile,
                        JobTitle    = model.JobTitle,
                        NationalId  = model.NationalId,
                        CreatedTime = DateTime.Now,
                        CreatedUser = UserName
                    };

                    result.Add(partner);
                    _hrUnitOfWork.CompanyRepository.Add(partner);
                }

                datasource.Errors = SaveChanges(Language);
            }
            else
            {
                datasource.Errors = Models.Utils.ParseErrors(ModelState.Values);
            }

            // Return the inserted products - the Kendo PageDiv needs their ID which is generated by SQL server during insertion
            datasource.Data = (from m in models
                               join r in result on m.Name equals r.Name into g
                               from r in g.DefaultIfEmpty()
                               select new PartnersViewModel
            {
                Id = (r == null ? 0 : r.Id),
                Name = m.Name,
                Email = m.Email,
                Telephone = m.Telephone,
                Address = m.Address,
                CompanyId = m.CompanyId,
                AddressId = m.AddressId,
                Mobile = m.Mobile,
                JobTitle = m.JobTitle,
                NationalId = m.NationalId,
                CreatedTime = DateTime.Now,
                CreatedUser = UserName
            }).ToList();


            if (datasource.Errors.Count() > 0)
            {
                return(Json(datasource));
            }
            else
            {
                return(Json(datasource.Data));
            }
        }
Exemple #14
0
        public Model.Profile.Company.Entity.Company LoginCompany(CompanyPartner companyPartner)
        {
            try
            {
                StandartPersistence standartPersistence =
                    new StandartPersistence(this.Connection);
                Model.Profile.Company.Entity.Company company = new Model.Profile.Company.Entity.Company();
                string pass = CryptHelper.Encrypt(companyPartner.Password);
                companyPartner = standartPersistence.GetEntities <CompanyPartner>(CommandType.Text,
                                                                                  "SELECT * FROM CompanyPartner WHERE Email = @Email AND [Password] = @Password",
                                                                                  new
                {
                    Email    = companyPartner.Email,
                    Password = pass
                }).SingleOrDefault();

                if (companyPartner != null && companyPartner.Id > 0)
                {
                    StringBuilder selectCompany = new StringBuilder();
                    selectCompany.Append($@"select c.* from company c 
                                           join companypartner cp on cp.idcompany = c.id
                                           where cp.id= {companyPartner.Id} ");
                    company = standartPersistence.GetEntities <Model.Profile.Company.Entity.Company>(CommandType.Text, selectCompany.ToString()).SingleOrDefault();

                    company.CompanyPartners = new List <CompanyPartner>();

                    if (companyPartner.IsOwner == true)
                    {
                        string part = $@"select * from companypartner where idcompany ={company.Id}";
                        company.CompanyPartners = standartPersistence.GetEntities <CompanyPartner>(CommandType.Text, part).ToList();
                    }
                    else
                    {
                        company.CompanyPartners.Add(companyPartner);
                    }

                    StringBuilder selectAddress = new StringBuilder();
                    selectAddress.Append($@"SELECT a.* FROM Address a 
                                            INNER JOIN CompanyAddress ca ON a.Id = ca.IdAddress 
                                            INNER JOIN Company c ON c.Id = ca.IdCompany 
                                            WHERE c.Id = {company.Id}");

                    company.Address = new Address();
                    company.Address = standartPersistence.GetEntities <Address>(CommandType.Text, selectAddress.ToString()).SingleOrDefault();

                    company.Address.State = new State();
                    company.Address.State = standartPersistence.GetEntities <State>(CommandType.Text,
                                                                                    "SELECT IdEstate, UPPER(Name) AS Name, UF FROM State WHERE IdEstate = @IdEstate",
                                                                                    new { IdEstate = company.Address.IdEstate }).SingleOrDefault();

                    City city = new City();
                    city = standartPersistence.GetEntities <City>(CommandType.Text,
                                                                  "SELECT IdCity, Name, IdEstate FROM City WHERE IdCity = @IdCity",
                                                                  new { IdCity = company.Address.IdCity }).SingleOrDefault();

                    company.Address.State.Cities = new List <City>();
                    company.Address.State.Cities.Add(city);
                }
                else
                {
                    company = new Model.Profile.Company.Entity.Company();
                    company.CompanyPartners = new List <CompanyPartner>();
                }

                return(company);
            }
            catch (TransactionException e)
            {
                throw e;
            }
        }
 public DbEntityEntry <CompanyPartner> Entry(CompanyPartner partner)
 {
     return(Context.Entry(partner));
 }
 public void Add(CompanyPartner partner)
 {
     context.CompanyPartners.Add(partner);
 }
 public void Attach(CompanyPartner partner)
 {
     context.CompanyPartners.Attach(partner);
 }