Example #1
0
        public ActionResult CreateProjectUser(ProjectUserViewModel model)
        {
            UserBL           userBL = new UserBL();
            OperationDetails operationDetails;

            UserModel user = userBL.GetUserByPfid(model.Pfid);

            if (user != null)
            {
                if (user.RoleId == (int)EnumHelper.Role.SuperAdmin)
                {
                    return(Json(new { success = false, message = "Cannot assign project to admin user." }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                // If user not found in User table, get user from HRMS service.
                user = userBL.GetUserFromService(model.Pfid);

                if (user == null)
                {
                    return(Json(new { success = false, message = "Employee with this PFID does not exist." }, JsonRequestBehavior.AllowGet));
                }

                user.CreatedBy   = CurrentUser.Pfid;
                operationDetails = userBL.AddUser(user);

                if (operationDetails.OperationStatus != 1)
                {
                    return(Json(new { success = false, message = "Something went wrong!!" }, JsonRequestBehavior.AllowGet));
                }
            }

            ProjectMappingModel projectMapping = new ProjectMappingModel();

            projectMapping.Pfid           = model.Pfid;
            projectMapping.ProjectId      = model.ProjectId;
            projectMapping.IsProjectAdmin = model.IsAdmin ? 1 : 0;
            projectMapping.CreatedBy      = CurrentUser.Pfid;

            operationDetails = userBL.AddProjectMapping(projectMapping);

            if (operationDetails.OperationStatus == 1)
            {
                return(Json(new { success = true, message = "User added to project successfully." }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new { success = false, message = "Something went wrong!!" }, JsonRequestBehavior.AllowGet));
        }