Exemple #1
0
        public HttpResponseMessage UpdateRole([FromBody] Role role)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (role.RoleFunctions.Count.Equals(0))
                    {
                        throw new Exception("The Functions field is required.");
                    }

                    bool result = RolePL.Update(role);
                    return(result.Equals(true) ? Request.CreateResponse(HttpStatusCode.OK, "Role updated successfully.") : Request.CreateResponse(HttpStatusCode.BadRequest, "Request failed."));
                }
                else
                {
                    string errors = ModelStateValidation.GetErrorListFromModelState(ModelState);
                    if (role.RoleFunctions.Count.Equals(0))
                    {
                        errors += ", The Functions field is required.";
                    }
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.WriteError(ex);
                var response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
                return(response);
            }
        }
Exemple #2
0
 public HttpResponseMessage SaveFunction([FromBody] Function function)
 {
     try
     {
         if (ModelState.IsValid)
         {
             string errMsg = string.Empty;
             function.Status = StatusUtil.Status.Active.ToString();
             bool result = FunctionPL.Save(function, out errMsg);
             if (string.IsNullOrEmpty(errMsg))
             {
                 return(result.Equals(true) ? Request.CreateResponse(HttpStatusCode.OK, "Function added successfully.") : Request.CreateResponse(HttpStatusCode.BadRequest, "Request failed"));
             }
             else
             {
                 var response = Request.CreateResponse(HttpStatusCode.BadRequest, errMsg);
                 return(response);
             }
         }
         else
         {
             string errors = ModelStateValidation.GetErrorListFromModelState(ModelState);
             return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
         }
     }
     catch (Exception ex)
     {
         ErrorHandler.WriteError(ex);
         var response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
         return(response);
     }
 }
 public HttpResponseMessage SaveBranch([FromBody] Branch branch)
 {
     try
     {
         if (ModelState.IsValid)
         {
             string errMsg = string.Empty;
             bool   result = BranchPL.Save(branch, out errMsg);
             if (string.IsNullOrEmpty(errMsg))
             {
                 return(result.Equals(true) ? Request.CreateResponse(HttpStatusCode.OK, "Branch added successfully.") : Request.CreateResponse(HttpStatusCode.BadRequest, "Request failed"));
             }
             else
             {
                 var response = Request.CreateResponse(HttpStatusCode.BadRequest, errMsg);
                 return(response);
             }
         }
         else
         {
             string errors = ModelStateValidation.GetErrorListFromModelState(ModelState);
             return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
         }
     }
     catch (Exception ex)
     {
         ErrorHandler.WriteError(ex);
         var response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
         return(response);
     }
 }
        public HttpResponseMessage SaveUser([FromBody] User user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //if (Mail.networkIsAvailable())
                    //{
                    string errMsg = string.Empty;
                    user.CreatedOn = System.DateTime.Now;
                    user.FirstTime = true;
                    string password = System.Web.Security.Membership.GeneratePassword(8, 0);
                    user.HashedPassword = PasswordHash.MD5Hash(password);

                    bool result = UserPL.Save(user, out errMsg);
                    if (string.IsNullOrEmpty(errMsg))
                    {
                        if (result)
                        {
                            user.HashedPassword = password;
                            Mail.SendNewUserMail(user);
                            return(Request.CreateResponse(HttpStatusCode.OK, "User added successfully."));
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Request failed"));
                        }
                    }
                    else
                    {
                        var response = Request.CreateResponse(HttpStatusCode.BadRequest, errMsg);
                        return(response);
                    }
                    //}
                    //else
                    //{
                    //return Request.CreateResponse(HttpStatusCode.BadRequest, "Kindly ensure that internet connection is available before creating a user");
                    //}
                }
                else
                {
                    string errors = ModelStateValidation.GetErrorListFromModelState(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.WriteError(ex);
                var response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
                return(response);
            }
        }
Exemple #5
0
        public HttpResponseMessage SaveRole([FromBody] Role role)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (role.RoleFunctions.Count.Equals(0))
                    {
                        throw new Exception("The Functions field is required.");
                    }

                    string errMsg = string.Empty;
                    role.Status = StatusUtil.Status.Active.ToString();
                    bool result = RolePL.Save(role, out errMsg);
                    if (string.IsNullOrEmpty(errMsg))
                    {
                        return(result.Equals(true) ? Request.CreateResponse(HttpStatusCode.OK, "Role added successfully.") : Request.CreateResponse(HttpStatusCode.BadRequest, "Request failed."));
                    }
                    else
                    {
                        var response = Request.CreateResponse(HttpStatusCode.BadRequest, errMsg);
                        return(response);
                    }
                }
                else
                {
                    string errors = ModelStateValidation.GetErrorListFromModelState(ModelState);
                    if (role.RoleFunctions.Count.Equals(0))
                    {
                        errors += ", The Functions field is required.";
                    }
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.WriteError(ex);
                var response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
                return(response);
            }
        }
Exemple #6
0
 public HttpResponseMessage UpdateFunction([FromBody] Function function)
 {
     try
     {
         if (ModelState.IsValid)
         {
             bool result = FunctionPL.Update(function);
             return(result.Equals(true) ? Request.CreateResponse(HttpStatusCode.OK, "Function updated successfully") : Request.CreateResponse(HttpStatusCode.BadRequest, "Request failed"));
         }
         else
         {
             string errors = ModelStateValidation.GetErrorListFromModelState(ModelState);
             return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
         }
     }
     catch (Exception ex)
     {
         ErrorHandler.WriteError(ex);
         var response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
         return(response);
     }
 }
 public HttpResponseMessage UpdateUser([FromBody] User user)
 {
     try
     {
         if (ModelState.IsValid)
         {
             bool result = UserPL.Update(user);
             return(result.Equals(true) ? Request.CreateResponse(HttpStatusCode.OK, "User Updated Successfully.") : Request.CreateResponse(HttpStatusCode.BadRequest, "Failed"));
         }
         else
         {
             string errors = ModelStateValidation.GetErrorListFromModelState(ModelState);
             return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
         }
     }
     catch (Exception ex)
     {
         ErrorHandler.WriteError(ex);
         var response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
         return(response);
     }
 }
        public HttpResponseMessage ConfigureSystem([FromBody] SystemModel systemModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string errMsg = "";

                    //Configure JS File used by all APIs (configFile.js)
                    string configFilepath = System.Web.Hosting.HostingEnvironment.MapPath(@"~/Scripts/Utility/configFile.js");
                    string jsSettings     = "var settingsManager = {\"websiteURL\": \"" + systemModel.WebsiteUrl + "\"};";

                    var lines = File.ReadAllLines(configFilepath);
                    lines[0] = jsSettings;
                    File.WriteAllLines(configFilepath, lines);


                    var configuration = WebConfigurationManager.OpenWebConfiguration("~");

                    var appSettingsSection = (AppSettingsSection)configuration.GetSection("appSettings");
                    appSettingsSection.Settings["Organization"].Value    = systemModel.Organization;
                    appSettingsSection.Settings["ApplicationName"].Value = systemModel.ApplicationName;
                    appSettingsSection.Settings["WebsiteUrl"].Value      = systemModel.WebsiteUrl;
                    appSettingsSection.Settings["PersoFilePath"].Value   = systemModel.PersoFilePath;

                    var section = (ConnectionStringsSection)configuration.GetSection("connectionStrings");
                    section.ConnectionStrings["PersoDBEntities"].ConnectionString = GetConnectionString(systemModel.DatabaseServer, systemModel.DatabaseName, systemModel.DatabaseUser, systemModel.DatabasePassword);

                    var mailHelperSection = (MailHelper)configuration.GetSection("mailHelperSection");
                    mailHelperSection.Mail.FromEmailAddress = systemModel.FromEmailAddress;
                    mailHelperSection.Mail.Username         = systemModel.SmtpUsername;
                    mailHelperSection.Mail.Password         = systemModel.SmtpPassword;

                    mailHelperSection.Smtp.Host = systemModel.SmtpHost;
                    mailHelperSection.Smtp.Port = systemModel.SmtpPort;

                    configuration.Save();


                    bool result = true;

                    if (string.IsNullOrEmpty(errMsg))
                    {
                        return(result.Equals(true) ? Request.CreateResponse(HttpStatusCode.OK, "Successful") : Request.CreateResponse(HttpStatusCode.BadRequest, "Request failed"));
                    }
                    else
                    {
                        var response = Request.CreateResponse(HttpStatusCode.BadRequest, errMsg);
                        return(response);
                    }
                }
                else
                {
                    string errors = ModelStateValidation.GetErrorListFromModelState(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.WriteError(ex);
                var response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
                return(response);
            }
        }