Пример #1
0
        public void SaveEmployee(ClientEmployee emp)
        {
            var query = $@"
INSERT INTO [dbo].[Employee](ID , IDNumber, FirstName, LastName, AccountNumber, BankCode, BusinessUnit, Position, Salary, CardNumber, PayFrequency, PayDate, PaymentType, EmployeeStatus, SyncDate)
VALUES
('{emp.ID}', '{emp.IdNumber}', '{emp.FirstName}', '{emp.LastName}', '{emp.AccountNumber}', {emp.Bank.BankId}, '{emp.BusinessUnit}', '{emp.Position}', {emp.Salary}, '{emp.CardNumber}'
, {(int)emp.PayFrequency}, {emp.PayDate}, {(int)emp.PaymentType}, {(int)emp.EmployeeStatus}, '{emp.SyncDate.ToString("yyyy-MM-dd HH:mm:ss")}')";

            using (var conn = getConnection())
            {
                if (isConnectionValid(conn))
                {
                    try
                    {
                        using (var command = new SqlCommand())
                        {
                            command.CommandText = query;
                            command.CommandType = CommandType.Text;
                            command.Connection  = conn;
                            conn.Open();

                            command.ExecuteNonQuery();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new ExceptionLogger(this.logger, "Could not save the Client Employee.", ex);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,PhoneNumber,EmailAddress")] ClientEmployee clientEmployee)
        {
            if (id != clientEmployee.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(clientEmployee);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClientEmployeeExists(clientEmployee.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(clientEmployee));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ClientEmployee clientemployee = db.ClientEmployees.Find(id);

            db.ClientEmployees.Remove(clientemployee);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "ClientEmployeeId,FirstName,LastName,ClientId")] ClientEmployee clientemployee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(clientemployee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ClientId = new SelectList(db.Clients, "ClientId", "Name", clientemployee.ClientId);
     return(View(clientemployee));
 }
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,PhoneNumber,EmailAddress")] ClientEmployee clientEmployee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(clientEmployee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(clientEmployee));
        }
Пример #6
0
        public IActionResult SaveEmployee([FromBody] Employee model)
        {
            if (model == null)
            {
                return(BadRequest("Error, Make sure form is complete!"));
            }

            try
            {
                Employee employee   = new Employee();
                Employee isEmployee = _context.Employees.FirstOrDefault(id => (id.Email == model.Email) && (id.TenantId == model.TenantId) && (id.ClientId == model.ClientId));
                if (isEmployee == null)
                {
                    employee.DateStamp   = DateTime.Now;
                    employee.Email       = model.Email;
                    employee.Name        = model.Name;
                    employee.Surname     = model.Surname;
                    employee.Reference   = model.Reference;
                    employee.Title       = model.Title;
                    employee.IsSendEmail = model.IsSendEmail;
                    employee.ClientId    = model.ClientId;
                    employee.TenantId    = model.TenantId;
                    employee.AssetNodeId = model.AssetNodeId;
                    employee.Identifier  = Guid.NewGuid();

                    _context.Employees.Add(employee);
                    _context.SaveChanges();
                }


                ClientEmployee isClientEmployee = _context.ClientEmployees.FirstOrDefault(id => (id.TenantId == model.TenantId) && (id.ClientId == model.ClientId) && (id.EmployeeId == model.EmployeeId));

                if (isClientEmployee == null)
                {
                    ClientEmployee clientEmployee = new ClientEmployee();
                    clientEmployee.DateStamp  = DateTime.Now;
                    clientEmployee.ClientId   = model.ClientId;
                    clientEmployee.TenantId   = model.TenantId;
                    clientEmployee.EmployeeId = employee.EmployeeId;
                    clientEmployee.Reference  = model.Reference;

                    _context.ClientEmployees.Add(clientEmployee);
                    _context.SaveChanges();
                }


                return(Ok());
            }
            catch (Exception Ex)
            {
                return(BadRequest("Something bad happened! " + Ex.Message));
            }
        }
        // GET: /Employee/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ClientEmployee clientemployee = db.ClientEmployees.Find(id);

            if (clientemployee == null)
            {
                return(HttpNotFound());
            }
            return(View(clientemployee));
        }
        // GET: /Employee/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ClientEmployee clientemployee = db.ClientEmployees.Find(id);

            if (clientemployee == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ClientId = new SelectList(db.Clients, "ClientId", "Name", clientemployee.ClientId);
            return(View(clientemployee));
        }
        public ClientEmployee Update(ClientEmployee clientEmployee)
        {
            var newClientEmployee = _context.ClientEmployees.Update(clientEmployee);

            if (newClientEmployee != null && newClientEmployee.State == EntityState.Added)
            {
                var affectedRows = _context.SaveChanges();

                if (affectedRows > 0)
                {
                    return(newClientEmployee.Entity);
                }
            }

            return(null);
        }
        public Task <ServiceResult <EmployeeModel> > AddAsync(EmployeeModel model)
        {
            return(Task.Run(() =>
            {
                using (var context = _contextFactory.Create())
                {
                    var entity = new ClientEmployee();
                    _mapper.Map(model, entity);

                    context.Employees.Add(entity);
                    context.SaveChanges();

                    _mapper.Map(entity, model);

                    _employees.AddOrUpdate(model);

                    return ServiceResult.Ok(model);
                }
            }));
        }
Пример #11
0
        public static ClientEmployee ReadEmployees(int clientUID)
        {
            ClientEmployee clientEmployee = new ClientEmployee();

            clientEmployee.AdministrationPerson     = Read(clientUID, FCMConstant.RoleTypeCode.AdministrationPerson);
            clientEmployee.ManagingDirector         = Read(clientUID, FCMConstant.RoleTypeCode.ManagingDirector);
            clientEmployee.HealthAndSafetyRep       = Read(clientUID, FCMConstant.RoleTypeCode.HealthAndSafetyRep);
            clientEmployee.LeadingHand1             = Read(clientUID, FCMConstant.RoleTypeCode.LeadingHand1);
            clientEmployee.LeadingHand2             = Read(clientUID, FCMConstant.RoleTypeCode.LeadingHand2);
            clientEmployee.LeadingHand2             = Read(clientUID, FCMConstant.RoleTypeCode.LeadingHand2);
            clientEmployee.OHSEAuditor              = Read(clientUID, FCMConstant.RoleTypeCode.OHSEAuditor);
            clientEmployee.ProjectManager           = Read(clientUID, FCMConstant.RoleTypeCode.ProjectManager);
            clientEmployee.ProjectOHSRepresentative = Read(clientUID, FCMConstant.RoleTypeCode.ProjectOHSRepresentative);
            clientEmployee.SiteManager              = Read(clientUID, FCMConstant.RoleTypeCode.SiteManager);
            clientEmployee.Supervisor     = Read(clientUID, FCMConstant.RoleTypeCode.Supervisor);
            clientEmployee.SystemsManager = Read(clientUID, FCMConstant.RoleTypeCode.SystemsManager);
            clientEmployee.WorkersCompensationCoordinator = Read(clientUID, FCMConstant.RoleTypeCode.WorkersCompensationCoordinator);

            return(clientEmployee);
        }
Пример #12
0
        public List <ClientEmployee> getEmployees(string whereClause)
        {
            List <ClientEmployee> employees = new List <ClientEmployee>();
            var query = "SELECT * FROM [dbo].[Employee]";

            if (!whereClause.IsNullOrEmpty())
            {
                query += $" {whereClause}";
            }

            using (var conn = getConnection())
            {
                if (isConnectionValid(conn))
                {
                    try
                    {
                        using (var command = new SqlCommand())
                        {
                            command.CommandText = query;
                            command.CommandType = CommandType.Text;
                            command.Connection  = conn;
                            conn.Open();
                            using (var reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    var    bCode     = (BankCode)reader[5].ToString().GetEnum(typeof(BankCode));
                                    var    payFreq   = (PayFrequency)reader[10].ToString().GetEnum(typeof(PayFrequency));
                                    var    payType   = (ClientPaymentType)reader[12].ToString().GetEnum(typeof(ClientPaymentType));
                                    var    empStatus = (EmployeeStatus)reader[13].ToString().GetEnum(typeof(EmployeeStatus));
                                    var    salary    = reader[8].ToString();
                                    double castSalary;

                                    if (!double.TryParse(salary, out castSalary))
                                    {
                                        throw new ExceptionLogger(this.logger, $"Could not parse balance into a double.");
                                    }

                                    var emp = new ClientEmployee()
                                    {
                                        ID            = reader[0].ToString(),
                                        IdNumber      = reader[1].ToString(),
                                        FirstName     = reader[2].ToString(),
                                        LastName      = reader[3].ToString(),
                                        AccountNumber = reader[4].ToString(),
                                        Bank          = new ClientBank()
                                        {
                                            BankId = (int)bCode, BankName = bCode.ToString()
                                        },
                                        BusinessUnit   = reader[6].ToString(),
                                        Position       = reader[7].ToString(),
                                        Salary         = castSalary,
                                        CardNumber     = reader[9].ToString(),
                                        PayFrequency   = payFreq,
                                        PayDate        = Convert.ToInt32(reader[11].ToString()),
                                        PaymentType    = payType,
                                        EmployeeStatus = empStatus,
                                        SyncDate       = Convert.ToDateTime(reader[14])
                                    };

                                    employees.Add(emp);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new ExceptionLogger(this.logger, "Could not load the Clients Employees.", ex);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }

            return(employees);
        }
Пример #13
0
        public IHttpActionResult AddClientEmployee()
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var form  = HttpContext.Current.Request.Form;
                    var email = form.Get("Email");

                    UserManager <ApplicationUser> userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));

                    ClientEmployee clientEmp = new ClientEmployee();

                    clientEmp.FirstName      = form.Get("FirstName");
                    clientEmp.MiddleName     = form.Get("MiddleName");
                    clientEmp.LastName       = form.Get("LastName");
                    clientEmp.Email          = email;
                    clientEmp.PrimaryPhone   = form.Get("PrimaryPhoneNum");
                    clientEmp.SecondaryPhone = form.Get("SecondaryPhoneNumber");
                    clientEmp.Client_Id      = Convert.ToInt32(form.Get("ClientId"));
                    clientEmp.Fax            = form.Get("Fax");
                    clientEmp.Department     = form.Get("Department");
                    clientEmp.LastUpdated    = DateTime.Now;
                    clientEmp.Active         = true;
                    clientEmp.UpdatedBy      = User.Identity.GetUserId();

                    var files = HttpContext.Current.Request.Files;


                    if (files.Count > 0)
                    {
                        for (int i = 0; i < files.Count; i++)
                        {
                            if (files.GetKey(i).Contains("ImageOne"))
                            {
                                var fileDirectory = HttpContext.Current.Server.MapPath("~/ClientContactsImages");

                                if (!Directory.Exists(fileDirectory))
                                {
                                    Directory.CreateDirectory(fileDirectory);
                                }
                                var fileName = files[i].FileName;
                                var filePath = Path.Combine(fileDirectory, fileName);
                                files[i].SaveAs(filePath);
                                clientEmp.ImageOne = Path.Combine(ConfigurationManager.AppSettings["ApiUrl"], "ClientContactsImages", fileName);
                            }

                            else
                            {
                                var fileDirectory = HttpContext.Current.Server.MapPath("~/ClientContactsImages");
                                if (!Directory.Exists(fileDirectory))
                                {
                                    Directory.CreateDirectory(fileDirectory);
                                }
                                var fileName = files[i].FileName;
                                var filePath = Path.Combine(fileDirectory, fileName);
                                files[i].SaveAs(filePath);
                                clientEmp.ImageTwo = Path.Combine(ConfigurationManager.AppSettings["ApiUrl"], "ClientContactsImages", fileName);
                            }
                        }
                    }

                    // to send email to client employee
                    //string organisation = db.Organisations.Where(x => x.Id == OrgId).FirstOrDefault().OrgName;

                    //var user = userManager.FindByEmail(email);
                    //if (user != null)
                    //{
                    //    return Content(HttpStatusCode.InternalServerError, "User with email " + email + " already exists");
                    //}

                    //var userCreated = new UserController().CreateUser(email, email, "ClientEmployee", organisation);


                    //var userId = userManager.FindByEmail(email);
                    //if (user != null)
                    //{
                    //    clientEmp.AspNetUserId = user.Id;
                    //}

                    db.ClientEmployees.Add(clientEmp);
                    db.SaveChanges();
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
                return(Content(HttpStatusCode.InternalServerError, "An error occoured, please try again!"));
            }
        }
        /// <summary>
        /// Add Employee
        /// </summary>
        /// <param name="clientAddRequest"></param>
        /// <param name="employeeName"> </param>
        /// <param name="roleType"></param>
        private static void SaveEmployees(int clientUID, ClientEmployee inClientEmployee, string userID)
        {
            ClientEmployee clientEmployee = new ClientEmployee();

            clientEmployee = RepEmployee.ReadEmployees(clientUID);

            // ManagingDirector
            if (string.IsNullOrEmpty(clientEmployee.ManagingDirector))
            {
                AddEmployee(inClientEmployee.ManagingDirector, FCMConstant.RoleTypeCode.ManagingDirector, userID, clientUID);
            }
            else
            {
                UpdateEmployee(inClientEmployee.ManagingDirector, FCMConstant.RoleTypeCode.ManagingDirector, userID, clientUID);
            }

            // ProjectManager
            if (string.IsNullOrEmpty(clientEmployee.ProjectManager))
            {
                AddEmployee(inClientEmployee.ProjectManager, FCMConstant.RoleTypeCode.ProjectManager, userID, clientUID);
            }
            else
            {
                UpdateEmployee(inClientEmployee.ProjectManager, FCMConstant.RoleTypeCode.ProjectManager, userID, clientUID);
            }

            // ProjectOHSRepresentative
            if (string.IsNullOrEmpty(clientEmployee.ProjectOHSRepresentative))
            {
                AddEmployee(inClientEmployee.ProjectOHSRepresentative, FCMConstant.RoleTypeCode.ProjectOHSRepresentative, userID, clientUID);
            }
            else
            {
                UpdateEmployee(inClientEmployee.ProjectOHSRepresentative, FCMConstant.RoleTypeCode.ProjectOHSRepresentative, userID, clientUID);
            }

            // OHSEAuditor
            if (string.IsNullOrEmpty(clientEmployee.OHSEAuditor))
            {
                AddEmployee(inClientEmployee.ProjectOHSRepresentative, FCMConstant.RoleTypeCode.OHSEAuditor, userID, clientUID);
            }
            else
            {
                UpdateEmployee(inClientEmployee.ProjectOHSRepresentative, FCMConstant.RoleTypeCode.OHSEAuditor, userID, clientUID);
            }

            // SystemsManager
            if (string.IsNullOrEmpty(clientEmployee.SystemsManager))
            {
                AddEmployee(inClientEmployee.SystemsManager, FCMConstant.RoleTypeCode.SystemsManager, userID, clientUID);
            }
            else
            {
                UpdateEmployee(inClientEmployee.SystemsManager, FCMConstant.RoleTypeCode.SystemsManager, userID, clientUID);
            }

            // SiteManager
            if (string.IsNullOrEmpty(clientEmployee.SiteManager))
            {
                AddEmployee(inClientEmployee.SiteManager, FCMConstant.RoleTypeCode.SiteManager, userID, clientUID);
            }
            else
            {
                UpdateEmployee(inClientEmployee.SiteManager, FCMConstant.RoleTypeCode.SiteManager, userID, clientUID);
            }

            // Supervisor
            if (string.IsNullOrEmpty(clientEmployee.Supervisor))
            {
                AddEmployee(inClientEmployee.Supervisor, FCMConstant.RoleTypeCode.Supervisor, userID, clientUID);
            }
            else
            {
                UpdateEmployee(inClientEmployee.Supervisor, FCMConstant.RoleTypeCode.Supervisor, userID, clientUID);
            }

            // LeadingHand1
            if (string.IsNullOrEmpty(clientEmployee.LeadingHand1))
            {
                AddEmployee(inClientEmployee.LeadingHand1, FCMConstant.RoleTypeCode.LeadingHand1, userID, clientUID);
            }
            else
            {
                UpdateEmployee(inClientEmployee.LeadingHand1, FCMConstant.RoleTypeCode.LeadingHand1, userID, clientUID);
            }

            // LeadingHand2
            if (string.IsNullOrEmpty(clientEmployee.LeadingHand2))
            {
                AddEmployee(inClientEmployee.LeadingHand1, FCMConstant.RoleTypeCode.LeadingHand2, userID, clientUID);
            }
            else
            {
                UpdateEmployee(inClientEmployee.LeadingHand1, FCMConstant.RoleTypeCode.LeadingHand2, userID, clientUID);
            }

            // LeadingHand2
            if (string.IsNullOrEmpty(clientEmployee.HealthAndSafetyRep))
            {
                AddEmployee(inClientEmployee.LeadingHand1, FCMConstant.RoleTypeCode.HealthAndSafetyRep, userID, clientUID);
            }
            else
            {
                UpdateEmployee(inClientEmployee.LeadingHand1, FCMConstant.RoleTypeCode.HealthAndSafetyRep, userID, clientUID);
            }

            // AdministrationPerson
            if (string.IsNullOrEmpty(clientEmployee.HealthAndSafetyRep))
            {
                AddEmployee(inClientEmployee.AdministrationPerson, FCMConstant.RoleTypeCode.AdministrationPerson, userID, clientUID);
            }
            else
            {
                UpdateEmployee(inClientEmployee.AdministrationPerson, FCMConstant.RoleTypeCode.AdministrationPerson, userID, clientUID);
            }

            // WorkersCompensationCoordinator
            if (string.IsNullOrEmpty(clientEmployee.HealthAndSafetyRep))
            {
                AddEmployee(inClientEmployee.WorkersCompensationCoordinator, FCMConstant.RoleTypeCode.WorkersCompensationCoordinator, userID, clientUID);
            }
            else
            {
                UpdateEmployee(inClientEmployee.WorkersCompensationCoordinator, FCMConstant.RoleTypeCode.WorkersCompensationCoordinator, userID, clientUID);
            }
        }
Пример #15
0
 public void AddESM(ClientEmployee ESM)
 {
     db.ClientEmployees.Add(ESM);
     db.SaveChanges();
 }
Пример #16
0
        public ActionResult BeatHierarchyAddition()
        {
            List <FileHeadersBeatHierarchy> list = (List <FileHeadersBeatHierarchy>)Session["BeatHierarchy"];
            int?id    = (int?)Session["CompanyID"];
            int newId = id ?? default(int);
            var list1 = list.GroupBy(x => x.NSM);


            foreach (var keyitem in list1)
            {
                foreach (var item in keyitem)
                {
                    NationalSalesManager NSM = new NationalSalesManager
                    {
                        Name             = keyitem.Key,
                        EmailId          = item.NSMEmailId,
                        SecondaryEmailId = item.NSMSecondaryEmailId,
                        Zone             = item.NSMZone,
                        CompanyId        = newId
                    };
                    NSMRepository NSMRepo = new NSMRepository();
                    List <NationalSalesManager> NSMList = NSMRepo.GetNSM(newId);

                    if (!NSMList.Exists(x => x.Name == NSM.Name))
                    {
                        NSMRepo.AddNSM(NSM);
                    }
                    //Insert Regions
                    long NSMPk = db.NationalSalesManagers.Where(x => x.Name == item.NSM).Select(x => x.Id).FirstOrDefault();

                    ZonalSalesManager ZSM = new ZonalSalesManager();
                    ZSM.Name                   = item.ZSM;
                    ZSM.EmailId                = item.ZSMEmailId;
                    ZSM.SecondaryEmailId       = item.ZSMSecondaryEmailId;
                    ZSM.Zone                   = item.ZSMZone;
                    ZSM.NationalSalesManagerId = NSMPk;
                    ZSM.CompanyId              = newId;


                    ZSMRepository            ZSMRepo = new ZSMRepository();
                    List <ZonalSalesManager> ZSMList = ZSMRepo.GetZSM(newId);
                    if (!ZSMList.Exists(x => x.Name == ZSM.Name))
                    {
                        ZSMRepo.AddZSM(ZSM);
                    }

                    long ZSMPk = db.ZonalSalesManagers.Where(x => x.Name == item.ZSM).Select(x => x.Id).FirstOrDefault();

                    RegionalSalesManager RSM = new RegionalSalesManager();
                    RSM.Name                = item.RSM;
                    RSM.EmailId             = item.RSMEmailId;
                    RSM.SecondaryEmailId    = item.RSMSecondaryEmailId;
                    RSM.Zone                = item.RSMZone;
                    RSM.ZonalSalesManagerId = ZSMPk;
                    RSM.CompanyId           = newId;

                    RSMRepository RSMRepo = new RSMRepository();
                    List <RegionalSalesManager> RSMList = RSMRepo.GetRSM(newId);
                    if (!RSMList.Exists(x => x.Name == RSM.Name))
                    {
                        RSMRepo.AddRSM(RSM);
                    }

                    long RSMPk = db.RegionalSalesManagers.Where(x => x.Name == item.RSM).Select(x => x.Id).FirstOrDefault();

                    AreaSalesManager ASM = new AreaSalesManager();
                    ASM.Name                   = item.ASM;
                    ASM.EmailId                = item.ASMEmailId;
                    ASM.SecondaryEmailId       = item.ASMSecondaryEmailId;
                    ASM.Zone                   = item.ASMZone;
                    ASM.RegionalSalesManagerId = RSMPk;
                    ASM.CompanyId              = newId;

                    ASMRepository           ASMRepo = new ASMRepository();
                    List <AreaSalesManager> ASMList = ASMRepo.GetASM(newId);
                    if (!ASMList.Exists(x => x.Name == ASM.Name))
                    {
                        ASMRepo.AddASM(ASM);
                    }

                    long ASMPk = db.ClientEmployees.Where(x => x.Name == item.ASM).Select(x => x.Id).FirstOrDefault();

                    ClientEmployee ESM = new ClientEmployee();
                    ESM.Name             = item.ESM;
                    ESM.EmailId          = item.ESMEmailId;
                    ESM.SecondaryEmailId = item.ESMSecondaryEmailId;
                    //   ESM.Zone = item.ESMZone;
                    ESM.ClientSideId       = item.ESMErpId;
                    ESM.AreaSalesManagerId = ASMPk;
                    ESM.Company            = newId;

                    ESMRepository         ESMRepo = new ESMRepository();
                    List <ClientEmployee> ESMList = ESMRepo.GetESM(newId);
                    if (!ESMList.Exists(x => x.Name == ESM.Name))
                    {
                        ESMRepo.AddESM(ESM);
                    }

                    LocationBeat BEAT = new LocationBeat();
                    BEAT.Name         = item.FinalBeatName;
                    BEAT.ErpId        = item.BeatErpId;
                    BEAT.City         = item.BeatDistrict;
                    BEAT.State        = item.BeatState;
                    BEAT.DivisionZone = item.BeatZone;

                    BEATRepository      BEATRepo = new BEATRepository();
                    List <LocationBeat> BEATList = BEATRepo.GetBEAT(newId);

                    if (!BEATList.Exists(x => x.Name == BEAT.Name))
                    {
                        BEATRepo.AddBEAT(BEAT);
                    }
                    Distributor Distributor = new Distributor();
                    Distributor.Name         = item.DistributorName;
                    Distributor.EmailId      = item.DistributorEmailId;
                    Distributor.ClientSideId = item.DistributorErpId;
                    Distributor.Place        = item.DistributorLocation;

                    DistributorRepository DistributorRepo = new DistributorRepository();
                    List <Distributor>    DIstributorList = DistributorRepo.GetDistributor(newId);

                    if (!DIstributorList.Exists(x => x.Name == Distributor.Name))
                    {
                        DistributorRepo.AddDistributor(Distributor);
                    }

                    DistributorBeatMappingRepository DBMRepo = new DistributorBeatMappingRepository();
                    List <DistributorBeatMapping>    DBMList = DBMRepo.GetDistributorBeatMap(newId);

                    long BeatId        = db.LocationBeats.Where(x => x.Name == item.FinalBeatName).Select(x => x.Id).FirstOrDefault();
                    long DistributorId = db.Distributors.Where(x => x.Name == item.DistributorName).Select(x => x.Id).FirstOrDefault();

                    DistributorBeatMapping DBM = new DistributorBeatMapping();
                    DBM.BeatId        = BeatId;
                    DBM.DistributorId = DistributorId;
                    DBM.CompanyId     = newId;

                    if (!DBMList.Contains(DBM))
                    {
                        DBMRepo.AddDistributorBeatMap(DBM);
                    }
                }
            }
            return(View());
        }
Пример #17
0
        public async Task <IHttpActionResult> UpdateClientEmployee(int EmployeeId)
        {
            try
            {
                var form     = HttpContext.Current.Request.Form;
                var id       = form.Get("Id");
                var clientId = form.Get("ClientId");
                var oldMail  = form.Get("OldEmail");
                var email    = form.Get("Email");


                if (oldMail.ToLower() != email.ToLower())
                {
                    var userName = _userManager.FindByEmail(oldMail);
                    var userId   = userName.Id;

                    var exists = _userManager.FindByEmailAsync(email);
                    if (exists != null)
                    {
                        return(Content(HttpStatusCode.InternalServerError, "User with email " + email + "already exists"));
                    }

                    var res = await _userManager.SetEmailAsync(userId, email);
                }

                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    ClientEmployee clEmp = db.ClientEmployees.Find(Convert.ToInt32(id));

                    if (clEmp == null)
                    {
                        return(Content(HttpStatusCode.InternalServerError, "Invalid Data"));
                    }

                    clEmp.FirstName      = form.Get("FirstName").ToString();
                    clEmp.LastName       = form.Get("LastName").ToString();
                    clEmp.MiddleName     = form.Get("MiddleName").ToString();
                    clEmp.Email          = form.Get("Email");
                    clEmp.Fax            = form.Get("Fax").ToString();
                    clEmp.PrimaryPhone   = form.Get("PrimaryPhoneNum").ToString();
                    clEmp.SecondaryPhone = form.Get("SecondaryPhoneNum").ToString();
                    clEmp.LastUpdated    = DateTime.Now;
                    clEmp.Department     = form.Get("Department").ToString();
                    clEmp.Client_Id      = Convert.ToInt32(clientId);

                    //   clEmp.Active = true;

                    var files = HttpContext.Current.Request.Files;

                    if (files.Count > 0)
                    {
                        for (int i = 0; i < files.Count; i++)
                        {
                            if (files.GetKey(i).Contains("ImageOne"))
                            {
                                var fileDirectory = HttpContext.Current.Server.MapPath("~/ClientContactsImages");

                                if (!Directory.Exists(fileDirectory))
                                {
                                    Directory.CreateDirectory(fileDirectory);
                                }
                                var fileName = files[i].FileName;
                                var filePath = Path.Combine(fileDirectory, fileName);
                                files[i].SaveAs(filePath);
                                clEmp.ImageOne = Path.Combine(ConfigurationManager.AppSettings["ApiUrl"], "ClientContactsImages", fileName);
                            }

                            else if (files.GetKey(i).Contains("ImageTwo"))
                            {
                                var fileDirectory = HttpContext.Current.Server.MapPath("~/ClientContactsImages");
                                if (!Directory.Exists(fileDirectory))
                                {
                                    Directory.CreateDirectory(fileDirectory);
                                }
                                var fileName = files[i].FileName;
                                var filePath = Path.Combine(fileDirectory, fileName);
                                files[i].SaveAs(filePath);
                                clEmp.ImageTwo = Path.Combine(ConfigurationManager.AppSettings["ApiUrl"], "ClientContactsImages", fileName);
                            }
                        }
                    }


                    db.Entry(clEmp).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
                return(Content(HttpStatusCode.InternalServerError, "An error occoured, please try again!"));
            }
        }