コード例 #1
0
        public ActionResult EditCustomer(Models.CustomerModels model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();

                    var queryCustomer = (from p in _dbContext.T_Customer
                                         where p.vCustomerName == model.custumerName
                                         select p).FirstOrDefault();

                    model._StatesList = Helper.Helper.GetUSAStates();
                    //queryCustomer.custumerName = model.custumerName;
                    queryCustomer.vCustomerAddress = model.customerAddress;
                    queryCustomer.vStateCode       = model.states;
                    queryCustomer.vCustomerCity    = model.customerCity;

                    _dbContext.SaveChanges();

                    JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContextContacts = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();

                    var queryContactsByCustomer = (from p in _dbContextContacts.T_ContactsByCustomer
                                                   where p.vCustomerName == model.custumerName
                                                   select p);

                    foreach (var item in queryContactsByCustomer)
                    {
                        _dbContextContacts.T_ContactsByCustomer.Remove(item);
                    }
                    _dbContextContacts.SaveChanges();

                    foreach (var item in model._ListContacts)
                    {
                        JneCommSitesDataLayer.T_ContactsByCustomer newContactByCustomer = new JneCommSitesDataLayer.T_ContactsByCustomer();

                        newContactByCustomer.vContactName  = item.contactName;
                        newContactByCustomer.vEmailContact = item.contactEmail;
                        newContactByCustomer.vPhoneContact = item.contactPhone;
                        newContactByCustomer.vAreaContact  = item.contactArea;
                        newContactByCustomer.vCustomerName = model.custumerName;

                        _dbContext.T_ContactsByCustomer.Add(newContactByCustomer);

                        _dbContext.SaveChanges();
                    }

                    return(Json(true));
                }
                catch (Exception error)
                {
                    return(Json(error.Message));
                }
            }
            return(Json("There is a error, Please try again."));
        }
コード例 #2
0
        public ActionResult CreateCustomer(Models.CustomerModels model)
        {
            if (ModelState.IsValid)
            {
                JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();

                var queryCustomer = (from p in _dbContext.T_Customer
                                     where p.vCustomerName == model.custumerName
                                     select p).FirstOrDefault();

                if (queryCustomer != null)
                {
                    ModelState.AddModelError(string.Empty, "The Customer already exist");
                    model._StatesList = Helper.Helper.GetUSAStates();
                    return(Json("The Customer already exist"));
                }

                JneCommSitesDataLayer.T_Customer newCustomer = new JneCommSitesDataLayer.T_Customer();

                newCustomer.vCustomerName    = model.custumerName;
                newCustomer.vCustomerAddress = model.customerAddress;
                newCustomer.vCustomerCity    = model.customerCity;
                newCustomer.vStateCode       = model.states;

                _dbContext.T_Customer.Add(newCustomer);
                _dbContext.SaveChanges();

                foreach (var item in model._ListContacts)
                {
                    JneCommSitesDataLayer.T_ContactsByCustomer newContactByCustomer = new JneCommSitesDataLayer.T_ContactsByCustomer();

                    newContactByCustomer.vContactName  = item.contactName;
                    newContactByCustomer.vEmailContact = item.contactEmail;
                    newContactByCustomer.vPhoneContact = item.contactPhone;
                    newContactByCustomer.vAreaContact  = item.contactArea;
                    newContactByCustomer.vCustomerName = model.custumerName;

                    _dbContext.T_ContactsByCustomer.Add(newContactByCustomer);

                    _dbContext.SaveChanges();
                }

                return(Json(true));
            }
            if (model._ListContacts == null)
            {
                return(Json("You need add a contact for the costumer."));
            }
            return(Json("There is a error, please try again."));
        }
コード例 #3
0
 public ActionResult CreateCertification(Models.CertificationModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();
             var existCertification = (from p in _dbContext.T_Certifications
                                       where p.vCertificationName == model.certificationName
                                       select p).FirstOrDefault();
             if (existCertification != null)
             {
                 ModelState.AddModelError(string.Empty, "The certification already exist");
                 return(View());
             }
             JneCommSitesDataLayer.T_Certifications newCertification = new JneCommSitesDataLayer.T_Certifications();
             newCertification.vCertificationName        = model.certificationName;
             newCertification.vCertificationDescription = model.certificationpDescription;
             _dbContext.T_Certifications.Add(newCertification);
             _dbContext.SaveChanges();
             return(RedirectToAction("CertificationsList", "Maintenance"));
         }
         catch (Exception error)
         {
             ModelState.AddModelError(string.Empty, error.Message);
             return(View());
         }
     }
     return(View());
 }
コード例 #4
0
        public ActionResult EditTechEvolutionCode(Models.TechEvolutionCodesModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();

                    var queryTechEvolutionCode = (from p in _dbContext.T_TechEvolutionCodes
                                                  where p.vTechEvolutionCodeName == model.techEvolutionCodeName
                                                  select p).FirstOrDefault();

                    queryTechEvolutionCode.vTechEvolutionCodeDescription = model.techEvolutionCodeDescription;

                    _dbContext.SaveChanges();
                    return(RedirectToAction("TechEvolutionCodesList", "Maintenance"));
                }
                catch (Exception error)
                {
                    ModelState.AddModelError(string.Empty, error.Message);
                    return(View());
                }
            }
            return(View());
        }
コード例 #5
0
        public ActionResult EditCrewRol(Models.CrewRolModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();

                    var queryCetification = (from p in _dbContext.T_CrewRoles
                                             where p.vCrewRoleName == model.crewRoleName
                                             select p).FirstOrDefault();

                    queryCetification.vCrewRoleDescription = model.crewRoleDescription;

                    _dbContext.SaveChanges();
                    return(RedirectToAction("CrewRolesList", "Maintenance"));
                }
                catch (Exception error)
                {
                    ModelState.AddModelError(string.Empty, error.Message);
                    return(View());
                }
            }
            return(View());
        }
コード例 #6
0
        public ActionResult EditRol(Models.RolModel rolModel, string[] roles)
        {
            if (ModelState.IsValid)
            {
                JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();

                var rolInfQuery = (from p in _dbContext.AspNetRoles
                                   where p.Name == rolModel.nameGroup
                                   select p).FirstOrDefault();

                rolInfQuery.Description = rolModel.GroupDescription;

                var operationByRol = (from p in _dbContext.AspNetRoles
                                      from d in _dbContext.T_Operations
                                      where p.Name == rolModel.nameGroup
                                      select p).FirstOrDefault();

                operationByRol.T_Operations.Clear();

                if (roles != null)
                {
                    foreach (string permisson in roles)
                    {
                        int operationID       = Convert.ToInt32(permisson);
                        var queryOperationsId = (from p in _dbContext.T_Operations
                                                 where p.biOperationsId == operationID
                                                 select p).First();
                        rolInfQuery.T_Operations.Add(queryOperationsId);
                        _dbContext.SaveChanges();
                    }
                }
                _dbContext.SaveChanges();
                TempData["Message"] = "Changes Saved";
                return(RedirectToAction("RolesIndex", "Maintenance"));
            }



            rolModel.nameGroup      = rolModel.nameGroup;
            rolModel.OperationsList = Helper.Helper.GetOperations(rolModel.nameGroup);
            return(View(rolModel));
        }
コード例 #7
0
        public ActionResult CreateRol(Models.RolModel model, string[] roles)
        {
            ApplicationDbContext context = new ApplicationDbContext();

            JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();
            JneCommSitesDataLayer.T_Operations selectedOperations         = new JneCommSitesDataLayer.T_Operations();

            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var role        = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();

            role.Name = model.nameGroup;
            roleManager.Create(role);

            var rolInformation = (from p in _dbContext.AspNetRoles
                                  where p.Name == model.nameGroup
                                  select p).First();

            rolInformation.Description = model.GroupDescription;

            if (roles != null)
            {
                foreach (string permisson in roles)
                {
                    int operationID       = Convert.ToInt32(permisson);
                    var queryOperationsId = (from p in _dbContext.T_Operations
                                             where p.biOperationsId == operationID
                                             select p).First();
                    rolInformation.T_Operations.Add(queryOperationsId);
                    _dbContext.SaveChanges();
                }
            }
            _dbContext.SaveChanges();

            TempData["Message"] = "Has successfully create the role";

            return(RedirectToAction("RolesIndex", "Maintenance"));

            ModelState.AddModelError("", "Please check for errors and try again.");

            return(View(model));
        }
コード例 #8
0
        public ActionResult Purchase(Models.ActivityLogsPurchase model)
        {
            if (ModelState.IsValid)
            {
                JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();

                string userName = HttpContext.User.Identity.Name;

                var queryCurrentActivityLog = (from p in _dbContext.T_ActivityLog
                                               where p.AspNetUsers.UserName == userName &&
                                               (p.dtEndWorkingDay == null)
                                               select p).FirstOrDefault();

                var queryPurchaseID = (from p in _dbContext.T_PurchaseType
                                       where p.vPurchaseTypeName == model.purchaseType
                                       select p.iPuchaseTypeID).FirstOrDefault();

                JneCommSitesDataLayer.T_Purchase newPurchase = new JneCommSitesDataLayer.T_Purchase();

                string invoiceName = "Nothing";
                newPurchase.iActivityLogID = queryCurrentActivityLog.iActivityLogID;
                newPurchase.Description    = model.description;

                newPurchase.iPuchaseTypeID      = queryPurchaseID;
                newPurchase.dtPurchaseEndDate   = Convert.ToDateTime(DateTime.Now);
                newPurchase.dtPurchaseStartDate = Convert.ToDateTime(model.startPurchaseCheckPoint, culture);
                newPurchase.dPrice    = Convert.ToDecimal(model.price);
                newPurchase.vPosition = model.position;
                _dbContext.T_Purchase.Add(newPurchase);


                if (model.documentToUpload != null)
                {
                    invoiceName = userName + "_" + model.description.Replace(" ", "") + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + "_" + Path.GetExtension(model.documentToUpload.FileName).Replace(" ", "");

                    string path = System.IO.Path.Combine(Server.MapPath("~/Documents/Invoices/"), invoiceName);
                    // file is uploaded
                    model.documentToUpload.SaveAs(path);
                }
                newPurchase.InvoiceName = invoiceName;
                _dbContext.SaveChanges();
                return(View(model));
            }
            else
            {
                return(RedirectToAction("CreateActivityLogOptions"));
            }
        }
コード例 #9
0
 public ActionResult CreateTaskProgress(Models.TaskProgress model)
 {
     if (ModelState.IsValid)
     {
         JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();
         JneCommSitesDataLayer.T_TaskProgress newTaskProgress          = new JneCommSitesDataLayer.T_TaskProgress();
         newTaskProgress.vTaskProgressName = model.taskName;
         newTaskProgress.vTaskDescription  = model.taskDescription;
         newTaskProgress.bCanLoadFile      = model.canUploadFile;
         newTaskProgress.bIsActive         = model.isActive;
         _dbContext.T_TaskProgress.Add(newTaskProgress);
         _dbContext.SaveChanges();
         return(RedirectToAction("TaskProgressList"));
     }
     ModelState.AddModelError(string.Empty, "There is an error, Try again.");
     return(View());
 }
コード例 #10
0
        public ActionResult EditSite(Models.SiteModel model)
        {
            if (ModelState.IsValid)
            {
                JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();

                var querySite = (from p in _dbContext.T_Sites
                                 where p.vSiteName == model.siteName
                                 select p).FirstOrDefault();

                querySite.vAddress               = model.siteAddress;
                querySite.vCity                  = model.siteCity;
                querySite.vStateCode             = model.states;
                querySite.vTechEvolutionCodeName = model.technology;
                querySite.vCustomerName          = model.customerName;
                querySite.AspNetUsers.Clear();


                HttpPostedFileBase fileContent = model.referalOrder;
                if (fileContent != null && fileContent.ContentLength > 0)
                {
                    // get a stream
                    var stream = fileContent.InputStream;
                    // and optionally write the file to disk
                    querySite.vReferalOrderName = (model.siteName + Path.GetExtension(fileContent.FileName)).Replace(" ", "");
                    string path = System.IO.Path.Combine(Server.MapPath("~/Documents/ReferalOrder/"), (model.siteName + Path.GetExtension(fileContent.FileName)).Replace(" ", ""));
                    // file is uploaded
                    fileContent.SaveAs(path);
                }

                if (model._ListCrew != null)
                {
                    foreach (var item in model._ListCrew)
                    {
                        var queryCrewuser = (from p in _dbContext.AspNetUsers
                                             where p.UserName == item
                                             select p).FirstOrDefault();
                        querySite.AspNetUsers.Add(queryCrewuser);
                    }
                }
                _dbContext.SaveChanges();

                return(Json(true));
            }
            return(Json("An error ocurred, please try again."));
        }
コード例 #11
0
        public ActionResult EditTaskProgress(Models.TaskProgress model, int taskProgressID)
        {
            if (ModelState.IsValid)
            {
                JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();

                var queryTaskProgress = (from p in _dbContext.T_TaskProgress
                                         where p.iTaskProgressID == taskProgressID
                                         select p).FirstOrDefault();

                queryTaskProgress.vTaskProgressName = model.taskName;
                queryTaskProgress.vTaskDescription  = model.taskDescription;
                queryTaskProgress.bCanLoadFile      = model.canUploadFile;
                queryTaskProgress.bIsActive         = model.isActive;

                _dbContext.SaveChanges();
                return(RedirectToAction("TaskProgressList"));
            }
            ModelState.AddModelError(string.Empty, "There is an error, Try again.");
            return(View());
        }
コード例 #12
0
        public ActionResult CreateCrewRol(Models.CrewRolModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();
                    var existCrewRole = (from p in _dbContext.T_CrewRoles
                                         where p.vCrewRoleName == model.crewRoleName
                                         select p).FirstOrDefault();
                    if (existCrewRole != null)
                    {
                        ModelState.AddModelError(string.Empty, "The crew role already exist");
                        return(View());
                    }

                    var queryCrewRole = (from p in _dbContext.AspNetRoles
                                         where p.Name == "CrewRole"
                                         select p).FirstOrDefault();

                    JneCommSitesDataLayer.T_CrewRoles newCrewRole = new JneCommSitesDataLayer.T_CrewRoles();
                    newCrewRole.vCrewRoleName        = model.crewRoleName;
                    newCrewRole.vCrewRoleDescription = model.crewRoleDescription;
                    newCrewRole.Id = queryCrewRole.Id;

                    _dbContext.T_CrewRoles.Add(newCrewRole);
                    _dbContext.SaveChanges();
                    return(RedirectToAction("CrewRolesList", "Maintenance"));
                }
                catch (Exception error)
                {
                    ModelState.AddModelError(string.Empty, error.Message);
                    return(View());
                }
            }
            return(View());
        }
コード例 #13
0
        public async Task <ActionResult> EditUser(Models.CreateUserModel model)
        {
            if (ModelState.IsValid)
            {
                JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();

                var aspNetUserQuery = (from p in _dbContext.AspNetUsers
                                       where p.UserName == model.UserName
                                       select p).FirstOrDefault();

                var actualRol = (from p in _dbContext.AspNetRoles
                                 where p.Name == model.UserGroup
                                 select p).FirstOrDefault();

                aspNetUserQuery.AspNetRoles.Clear();

                aspNetUserQuery.AspNetRoles.Add(actualRol);
                if (!string.IsNullOrEmpty(model.Password))
                {
                    var token = await UserManager.GeneratePasswordResetTokenAsync(aspNetUserQuery.Id);

                    var result = await UserManager.ResetPasswordAsync(aspNetUserQuery.Id, token, model.Password);
                }
                var userInf = (from p in _dbContext.T_UsersData
                               where p.Id == aspNetUserQuery.Id
                               select p).First();

                userInf.UserFirstName        = model.firstName;
                userInf.UserLastName         = model.LastName;
                userInf.NumDaysForPassChange = model.daysChangePass;

                _dbContext.SaveChanges();

                return(RedirectToAction("UsersIndex", "Maintenance"));
            }
            return(View(model));
        }
コード例 #14
0
        public ActionResult PaymentPeriod(JneCommSitesDataLayer.T_PaymentPeriod model)
        {
            JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();

            var paymentPeriodQuery = (from p in _dbContext.T_PaymentPeriod
                                      select p).FirstOrDefault();

            if (paymentPeriodQuery != null)
            {
                paymentPeriodQuery.dStartCutOffDate = model.dStartCutOffDate;
            }

            else
            {
                JneCommSitesDataLayer.T_PaymentPeriod newPaymentPeriod = new JneCommSitesDataLayer.T_PaymentPeriod();
                newPaymentPeriod.dStartCutOffDate       = DateTime.Now;
                newPaymentPeriod.siDaysForPaymentPeriod = 15;
                _dbContext.T_PaymentPeriod.Add(newPaymentPeriod);
            }

            _dbContext.SaveChanges();

            return(View(paymentPeriodQuery));
        }
コード例 #15
0
        public async Task <ActionResult> EditEmployee(Models.EmployeeModel model)
        {
            if (ModelState.IsValid)
            {
                JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();

                var aspNetUserQuery = (from p in _dbContext.AspNetUsers
                                       where p.UserName == model.UserName
                                       select p).FirstOrDefault();

                var actualRol = (from p in _dbContext.T_CrewRoles
                                 from d in p.AspNetUsers
                                 where d.Id == aspNetUserQuery.Id
                                 select p).FirstOrDefault();

                aspNetUserQuery.T_CrewRoles.Clear();

                aspNetUserQuery.T_CrewRoles.Add(actualRol);

                if (!string.IsNullOrEmpty(model.Password))
                {
                    var token = await UserManager.GeneratePasswordResetTokenAsync(aspNetUserQuery.Id);

                    var result = await UserManager.ResetPasswordAsync(aspNetUserQuery.Id, token, model.Password);
                }
                var userInf = (from p in _dbContext.T_UsersData
                               where p.Id == aspNetUserQuery.Id
                               select p).First();

                userInf.UserFirstName = model.firstName;
                userInf.UserLastName  = model.LastName;
                userInf.LaborHourPay  = Convert.ToDecimal(model.laborHour);
                userInf.IsBilingual   = model.isBilingual;
                //userInf.NumDaysForPassChange = model.daysChangePass;

                _dbContext.SaveChanges();

                JneCommSitesDataLayer.JneCommSitesDataBaseEntities _Context = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();


                var queryCertificationsByUser = (from p in _Context.T_CertificationsByUserCrew
                                                 where p.Id == aspNetUserQuery.Id
                                                 select p);

                foreach (var item in queryCertificationsByUser)
                {
                    _Context.T_CertificationsByUserCrew.Remove(item);
                }
                _Context.SaveChanges();


                foreach (var item in model._ListCertifications)
                {
                    if (item.isActive)
                    {
                        JneCommSitesDataLayer.T_CertificationsByUserCrew newCertificationByUser = new JneCommSitesDataLayer.T_CertificationsByUserCrew();
                        newCertificationByUser.vCertificationName = item.certificationName;
                        newCertificationByUser.Id = aspNetUserQuery.Id; if (item.expirationTime != null)
                        {
                            newCertificationByUser.dExpirationTime = Convert.ToDateTime(item.expirationTime);
                        }
                        if (item.documentToUpload != null)
                        {
                            newCertificationByUser.vDocumentName = (model.UserName + "_" + item.certificationName + Path.GetExtension(item.documentToUpload.FileName)).Replace(" ", "");

                            string path = System.IO.Path.Combine(
                                Server.MapPath("~/Documents/Certifications/"), (model.UserName + "_" + item.certificationName + Path.GetExtension(item.documentToUpload.FileName)).Replace(" ", ""));
                            // file is uploaded
                            item.documentToUpload.SaveAs(path);
                        }
                        _dbContext.T_CertificationsByUserCrew.Add(newCertificationByUser);
                        _dbContext.SaveChanges();
                    }
                }
                model._UserCrewGroup = Helper.Helper.GetSubRoles("CrewRole");
                model._StatesList    = Helper.Helper.GetUSAStates();
                return(RedirectToAction("CrewEmployeeIndex", "Administration"));
            }
            model._UserCrewGroup = Helper.Helper.GetSubRoles("CrewRole");
            model._StatesList    = Helper.Helper.GetUSAStates();
            return(View(model));
        }
コード例 #16
0
        public async Task <ActionResult> CreateUser(Models.CreateUserModel model)
        {
            if (ModelState.IsValid)
            {
                //BOSDataLayer.BackOfficeConn DB = new BOSDataLayer.BackOfficeConn();
                string UserName = model.UserName.Trim();

                try
                {
                    JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();

                    /*if ((from p in _dbContext.AspNetUsers where p.UserName == UserName select p.Id).Any())
                     * {
                     *  throw new Exception("This user name is not available.");
                     * }*/

                    var potentialUser = await UserManager.FindByNameAsync(model.UserName);

                    if (potentialUser != null)
                    {
                        throw new Exception("UserName@This user name is already taken");
                    }

                    potentialUser = await UserManager.FindByEmailAsync(model.Email);

                    if (potentialUser != null)
                    {
                        throw new Exception("Email@This email is already taken");
                    }
                    MembershipCreateStatus createStatusResult = MembershipCreateStatus.ProviderError;

                    var userProfile = new ApplicationUser {
                        UserName = model.UserName, Email = model.Email
                    };
                    var result = await UserManager.CreateAsync(userProfile, model.Password);

                    if (!result.Succeeded)
                    {
                        throw new Exception(result.Errors.FirstOrDefault().ToString());
                    }
                    else
                    {
                        await UserManager.SendEmailAsync(userProfile.Id, "Welcome to JNECommunications LLC", "This is your Username: "******"User was not created, please try again.");
                        }

                        var queryRol = (from p in _dbContext.AspNetRoles
                                        where p.Name == model.UserGroup
                                        select p).FirstOrDefault();

                        newUserData.Id                   = user.Id;
                        newUserData.UserFirstName        = model.firstName;
                        newUserData.UserLastName         = model.LastName;
                        newUserData.NumDaysForPassChange = model.daysChangePass;
                        newUserData.vStateCode           = "TX";
                        newUserData.UserDescription      = model.Description;
                        newUserData.ForcePassChange      = model.forcePassChange;

                        _dbContext.T_UsersData.Add(newUserData);
                        user.AspNetRoles.Add(queryRol);
                        user.LockoutEnabled = model.lockedOutUser;

                        _dbContext.SaveChanges();
                        _dbContext.Dispose();

                        TempData["Message"] = "User was created successfully";
                        return(RedirectToAction("UsersIndex", "Maintenance"));
                    }
                }
                catch (Exception err)
                {
                    model._UserGroup = Helper.Helper.GetRoles();
                    string[] tokens = err.Message.Split('@');
                    if (tokens.Length > 1)
                    {
                        ModelState.AddModelError(tokens[0], tokens[1]);
                    }
                    else
                    {
                        ModelState.AddModelError(String.Empty, err.Message);
                    }
                }
            }
            model._UserGroup = Helper.Helper.GetRoles();
            return(View(model));
        }
コード例 #17
0
        public ActionResult CreateSite(Models.SiteModel model)
        {
            if (ModelState.IsValid)
            {
                if (model._ListCrew == null)
                {
                    return(Json("You need add a Crew for the Site."));
                }

                try
                {
                    JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();

                    var querySite = (from p in _dbContext.T_Sites
                                     where p.vSiteName == model.siteName
                                     select p).FirstOrDefault();

                    if (querySite != null)
                    {
                        ModelState.AddModelError(string.Empty, "The Site already exist");
                        model._StatesList = Helper.Helper.GetUSAStates();
                        return(Json("The Site already exist"));
                    }


                    JneCommSitesDataLayer.T_Sites newSite = new JneCommSitesDataLayer.T_Sites();
                    newSite.vSiteName              = model.siteName;
                    newSite.vAddress               = model.siteAddress;
                    newSite.vCity                  = model.siteCity;
                    newSite.vStateCode             = model.states;
                    newSite.vCustomerName          = model.customerName;
                    newSite.vTechEvolutionCodeName = model.technology;


                    HttpPostedFileBase fileContent = model.referalOrder;
                    if (fileContent != null && fileContent.ContentLength > 0)
                    {
                        // get a stream
                        var stream = fileContent.InputStream;
                        // and optionally write the file to disk
                        newSite.vReferalOrderName = (model.siteName + Path.GetExtension(fileContent.FileName)).Replace(" ", "");
                        string path = System.IO.Path.Combine(Server.MapPath("~/Documents/ReferalOrder/"), (model.siteName + Path.GetExtension(fileContent.FileName)).Replace(" ", ""));
                        // file is uploaded
                        fileContent.SaveAs(path);
                    }


                    foreach (var item in model._ListCrew)
                    {
                        var queryCrewuser = (from p in _dbContext.AspNetUsers
                                             where p.UserName == item
                                             select p).FirstOrDefault();
                        newSite.AspNetUsers.Add(queryCrewuser);
                    }

                    _dbContext.T_Sites.Add(newSite);
                    _dbContext.SaveChanges();

                    return(Json(true));
                }
                catch (Exception error)
                {
                    return(Json(error.Message));
                }
            }
            return(Json("There is a error please try again"));
        }
コード例 #18
0
        public async Task <ActionResult> CreateEmployee(Models.EmployeeModel model)
        {
            if (ModelState.IsValid)
            {
                string UserName = model.UserName.Trim();

                try
                {
                    JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();


                    var potentialUser = await UserManager.FindByNameAsync(model.UserName);

                    if (potentialUser != null)
                    {
                        throw new Exception("UserName@This user name is already taken");
                    }

                    potentialUser = await UserManager.FindByEmailAsync(model.Email);

                    if (potentialUser != null)
                    {
                        throw new Exception("Email@This email is already taken");
                    }
                    MembershipCreateStatus createStatusResult = MembershipCreateStatus.ProviderError;

                    var userProfile = new ApplicationUser {
                        UserName = model.UserName, Email = model.Email
                    };
                    var result = await UserManager.CreateAsync(userProfile, model.Password);

                    if (!result.Succeeded)
                    {
                        throw new Exception(result.Errors.FirstOrDefault().ToString());
                    }
                    else
                    {
                        await UserManager.SendEmailAsync(userProfile.Id, "Welcome to JNECommunications LLC", "This is your Username: "******"User was not created, please try again.");
                        }

                        var queryRol = (from p in _dbContext.AspNetRoles
                                        where p.Name == "CrewRole"
                                        select p).FirstOrDefault();

                        var queryCrewRol = (from p in _dbContext.T_CrewRoles
                                            where p.vCrewRoleName == model.UserCrewGroup
                                            select p).FirstOrDefault();

                        newUserData.Id            = user.Id;
                        newUserData.UserFirstName = model.firstName;
                        newUserData.UserLastName  = model.LastName;
                        //newUserData.NumDaysForPassChange = model.daysChangePass;
                        newUserData.UserDescription = "User for crew";
                        //newUserData.ForcePassChange = model.forcePassChange;
                        newUserData.vStateCode   = model.states;
                        newUserData.LaborHourPay = Convert.ToDecimal(model.laborHour);
                        newUserData.IsBilingual  = model.isBilingual;

                        _dbContext.T_UsersData.Add(newUserData);
                        user.AspNetRoles.Add(queryRol);
                        user.T_CrewRoles.Add(queryCrewRol);
                        user.LockoutEnabled = model.lockedOutUser;

                        _dbContext.SaveChanges();


                        foreach (var item in model._ListCertifications)
                        {
                            if (item.isActive)
                            {
                                JneCommSitesDataLayer.T_CertificationsByUserCrew newCertificationByUser = new JneCommSitesDataLayer.T_CertificationsByUserCrew();
                                newCertificationByUser.vCertificationName = item.certificationName;
                                newCertificationByUser.Id = user.Id; if (item.expirationTime != null)
                                {
                                    newCertificationByUser.dExpirationTime = Convert.ToDateTime(item.expirationTime);
                                }
                                if (item.documentToUpload != null)
                                {
                                    newCertificationByUser.vDocumentName = (model.UserName + "_" + item.certificationName + Path.GetExtension(item.documentToUpload.FileName)).Replace(" ", "");

                                    string path = System.IO.Path.Combine(Server.MapPath("~/Documents/Certifications/"), (model.UserName + "_" + item.certificationName + Path.GetExtension(item.documentToUpload.FileName)).Replace(" ", ""));
                                    // file is uploaded
                                    item.documentToUpload.SaveAs(path);
                                }
                                _dbContext.T_CertificationsByUserCrew.Add(newCertificationByUser);
                                _dbContext.SaveChanges();
                            }
                        }


                        _dbContext.Dispose();

                        TempData["Message"] = "User was created successfully";
                        return(RedirectToAction("CrewEmployeeIndex", "Administration"));
                    }
                }
                catch (Exception err)
                {
                    model._UserCrewGroup = Helper.Helper.GetSubRoles("CrewRole");
                    model._StatesList    = Helper.Helper.GetUSAStates();
                    string[] tokens = err.Message.Split('@');
                    if (tokens.Length > 1)
                    {
                        ModelState.AddModelError(tokens[0], tokens[1]);
                    }
                    else
                    {
                        ModelState.AddModelError(String.Empty, err.Message);
                    }
                }
            }
            model._UserCrewGroup = Helper.Helper.GetSubRoles("CrewRole");
            model._StatesList    = Helper.Helper.GetUSAStates();
            return(View(model));
        }
コード例 #19
0
        public bool CheckPoint(string siteID, JneCommSitesDataLayer.T_ActivityLog activityLogID, string checkPointFor, string checkPoint, string position)
        {
            CultureInfo culture = new CultureInfo("en-US");

            JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();

            var queryUsersBySite = (from p in _dbContext.AspNetUsers
                                    from d in p.T_Sites
                                    where d.vSiteName == siteID
                                    select p);



            if (activityLogID == null && checkPointFor == "StartWorkingDay")
            {
                foreach (var item in queryUsersBySite)
                {
                    JneCommSitesDataLayer.T_ActivityLog newLogActivity = new JneCommSitesDataLayer.T_ActivityLog();
                    newLogActivity.Id = item.Id;
                    newLogActivity.dtStartWorkingDay        = Convert.ToDateTime(checkPoint, culture);
                    newLogActivity.vSiteName                = siteID;
                    newLogActivity.vStartWorkingDayPosition = position;
                    _dbContext.T_ActivityLog.Add(newLogActivity);
                }
                _dbContext.SaveChanges();
            }


            if (activityLogID != null && checkPointFor == "StartWorkingDay")
            {
                ModelState.AddModelError(string.Empty, "You should end a working day before start a new day. / Usted deberia finalizar la jornada de trabajo antes de iniciar una nueva.");
            }

            if (activityLogID != null && checkPointFor != "StartWorkingDay")
            {
                foreach (var item in queryUsersBySite)
                {
                    var queryExistLogActivity = (from p in _dbContext.T_ActivityLog
                                                 where p.AspNetUsers.UserName == item.UserName &&
                                                 p.dtEndWorkingDay == null
                                                 select p).FirstOrDefault();
                    if (checkPointFor == "ArrivingWareHouse" && queryExistLogActivity.dtArrivingToWareHouse != null)
                    {
                        ModelState.AddModelError(string.Empty, "The Arriving WareHouse have a Date assigned. / Usted ya ingreso una fecha para Llegada de bodega.");
                        break;
                    }
                    if (checkPointFor == "ArrivingWareHouse" && queryExistLogActivity.dtArrivingToWareHouse == null)
                    {
                        queryExistLogActivity.dtArrivingToWareHouse        = Convert.ToDateTime(checkPoint, culture);
                        queryExistLogActivity.vArrivingToWareHousePosition = position;
                    }
                    if (checkPointFor == "DepartureWareHouse" && queryExistLogActivity.dtDepartureFromWereHouse != null)
                    {
                        ModelState.AddModelError(string.Empty, "The Departure WareHouse have a Date assigned. / Usted ya ingreso una fecha para Salida de bodega.");
                        break;
                    }
                    if (checkPointFor == "DepartureWareHouse" && queryExistLogActivity.dtDepartureFromWereHouse == null)
                    {
                        queryExistLogActivity.dtDepartureFromWereHouse        = Convert.ToDateTime(checkPoint, culture);
                        queryExistLogActivity.vDepartureFromWereHousePosition = position;
                    }
                }
                _dbContext.SaveChanges();
            }

            if (activityLogID == null && checkPointFor != "StartWorkingDay")
            {
                ModelState.AddModelError(string.Empty, "Before to " + checkPointFor + " you need to start a working day. / Antes de llegar a la bodega usted necesita iniciar una jornada laboral.");
            }
            return(true);
        }
コード例 #20
0
        public ActionResult EndWorkingDay(Models.EndWorkingDayModel model, string[] taskProgressList, HttpPostedFileBase[] filesList, string[] filesName)
        {
            if (ModelState.IsValid)
            {
                CultureInfo culture = new CultureInfo("en-US");

                JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities();
                Random getrandom = new Random();

                string userName = HttpContext.User.Identity.Name;

                var queryCurrentActivityLog = (from p in _dbContext.T_ActivityLog
                                               where p.AspNetUsers.UserName == userName &&
                                               (p.dtEndWorkingDay == null)
                                               select p).FirstOrDefault();

                string fileName = "";
                if (filesName != null)
                {
                    for (int x = 0; x < filesName.Length; x++)
                    {
                        JneCommSitesDataLayer.T_FilesUploadedBySiteTaskProgress newFile = new JneCommSitesDataLayer.T_FilesUploadedBySiteTaskProgress();

                        int taskID = Convert.ToInt32(filesName[x].Replace(filesList[x].FileName, ""));


                        var queryTask = (from p in _dbContext.T_TaskProgress
                                         where p.iTaskProgressID == taskID
                                         select p).FirstOrDefault();

                        fileName = getrandom.Next(999) + "_" + queryTask.vTaskProgressName + "_" + filesList[x].FileName.Replace(" ", "").Replace("_", "");

                        newFile.iActivityLogID  = queryCurrentActivityLog.iActivityLogID;
                        newFile.iTaskProgressID = queryTask.iTaskProgressID;
                        newFile.vFileName       = fileName;
                        _dbContext.T_FilesUploadedBySiteTaskProgress.Add(newFile);
                        string path = System.IO.Path.Combine(Server.MapPath("~/Documents/PrePictures/"), fileName);
                        // file is uploaded
                        filesList[x].SaveAs(path);
                        _dbContext.SaveChanges();
                    }
                }

                if (taskProgressList != null)
                {
                    foreach (string task in taskProgressList)
                    {
                        int taskID    = Convert.ToInt32(task);
                        var queryTask = (from p in _dbContext.T_TaskProgress
                                         where p.iTaskProgressID == taskID
                                         select p).FirstOrDefault();
                        queryCurrentActivityLog.T_TaskProgress.Add(queryTask);
                        _dbContext.SaveChanges();
                    }
                }


                var queryUsersBySite = (from p in _dbContext.AspNetUsers
                                        from d in p.T_Sites
                                        where d.vSiteName == model.siteID
                                        select p);



                foreach (var item in queryUsersBySite)
                {
                    queryCurrentActivityLog = (from p in _dbContext.T_ActivityLog
                                               where p.AspNetUsers.UserName == item.UserName &&
                                               (p.dtEndWorkingDay == null)
                                               select p).FirstOrDefault();

                    queryCurrentActivityLog.dtEndWorkingDay        = Convert.ToDateTime(model.endWorkingDayCheckPoint, culture);
                    queryCurrentActivityLog.iProgress              = Convert.ToInt32(model.progress);
                    queryCurrentActivityLog.vNotes                 = model.notes;
                    queryCurrentActivityLog.vEndWorkingDayPosition = model.position;
                }
                _dbContext.SaveChanges();

                return(RedirectToAction("CreateActivityLogOptions"));
            }
            else
            {
                model._ProgressPercentageList = Helper.Helper.GetActivityProgress();
            }
            model._ProgressList = Helper.Helper.GetActivityLogOptions(0);
            return(View(model));
        }