public bool CreateNewEndUser(EndUsersDto NewUserRequest)
 {
     try
     {
         var IsUserExist = _Context.EndUsers.Where(x => x.FirstName == NewUserRequest.FirstName && x.LastName == NewUserRequest.LastName && x.EndUser_Company == NewUserRequest.EndUser_Company).FirstOrDefault();
         if (IsUserExist != null)
         {
             return(false);
         }
         EndUsers endUser = new EndUsers
         {
             FirstName        = NewUserRequest.FirstName,
             LastName         = NewUserRequest.LastName,
             EmployeeNo       = NewUserRequest.EmployeeNo,
             Department       = NewUserRequest.Department,
             CostCode         = NewUserRequest.CostCode,
             EndUserStatus    = NewUserRequest.EndUserStatus,
             CommencementDate = NewUserRequest.CommencementDate,
             TerminationDate  = NewUserRequest.TerminationDate,
             EndUser_Company  = NewUserRequest.EndUser_Company,
             EndUser_Site     = NewUserRequest.EndUser_Site
         };
         _Context.EndUsers.Add(endUser);
         _Context.SaveChanges();
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }
Exemple #2
0
        private static EndUsersDto CreateNewUserData(CreateEndUserModel createUser)
        {
            EndUsersDto createUserDto = new EndUsersDto
            {
                FirstName        = createUser.FirstName,
                LastName         = createUser.LastName,
                EmployeeNo       = createUser.EmployeeNo,
                Department       = createUser.Department,
                CostCode         = createUser.CostCode,
                EndUserStatus    = createUser.EndUserStatus,
                CommencementDate = createUser.CommencementDate,
                TerminationDate  = createUser.TerminationDate,
                EndUser_Company  = createUser.EndUser_Company,
                EndUser_Site     = createUser.EndUser_Site,
                Created          = DateTimeOffset.Now
            };

            return(createUserDto);
        }
Exemple #3
0
        public IActionResult CreateEndUsers([FromBody] CreateEndUserModel createUserModel)
        {
            ReturnModel returnmessage = new ReturnModel();

            if (!ModelState.IsValid == true)
            {
                return(BadRequest());
            }
            EndUsersDto newUserData   = CreateNewUserData(createUserModel);
            bool        IsUserCreated = _EndUsers.CreateNewEndUser(newUserData);

            if (IsUserCreated != true)
            {
                return(BadRequest());
            }
            returnmessage.Message = "EndUser Created";
            var returnvalue = JsonConvert.SerializeObject(returnmessage);

            return(Ok(returnvalue));
        }