public async Task <ActionResult> DeleteUser(string UserID)
        {
            try
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userData.AccessToken);
                HttpResponseMessage responseMessage = await client.PostAsJsonAsync(_url + "Account/DeleteUser/" + UserID, "");

                if (responseMessage.IsSuccessStatusCode)
                {
                    var result       = responseMessage.Content.ReadAsStringAsync().Result;
                    var statusResult = JsonConvert.DeserializeObject <StatusResult>(result);
                    if (statusResult.Status.Equals(Status.Success.ToString()))
                    {
                        Log.Info(Logfornet.LogMessage(UserID, "DeleteUser", ErrorMessages.Success, ""));
                        return(Json(statusResult.Status, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        Log.Info(Logfornet.LogMessage(UserID, "DeleteUser", statusResult.Status, ""));
                        errorMessage = statusResult.Status;
                    }
                }
                else
                {
                    Log.Info(Logfornet.LogMessage(UserID, "DeleteUser", responseMessage.StatusCode, ""));
                    errorMessage = responseMessage.StatusCode.ToString();
                }
                return(Json(errorMessage, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Log.Info(Logfornet.LogMessage(UserID, "DeleteUser", ex.Message, ""));
                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
Example #2
0
        public async Task <ActionResult> UpdateCustomer(CustomerProfile model)
        {
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userData.AccessToken);
            HttpResponseMessage responseMessage = await client.PostAsJsonAsync(_url + "Customer/UpdateCustomer", model);

            var result = responseMessage.Content.ReadAsStringAsync().Result;

            statusResult = JsonConvert.DeserializeObject <StatusResult>(result);
            if (responseMessage.IsSuccessStatusCode)
            {
                if (statusResult.Status.Equals(Status.Success.ToString()))
                {
                    return(Json(statusResult, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(statusResult, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                Log.Error(Logfornet.LogMessage(model.CompanyID, "UpdateCustomer", statusResult.Result, statusResult.Status));
            }
            return(View("Error"));
        }
        public StatusResult AddCustomer(CustomerProfile model)
        {
            StatusResult c = new Models.StatusResult();

            try
            {
                if (!ModelState.IsValid)
                {
                    var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => x.Value.Errors.Select(y => y.ErrorMessage)).ToList();
                    Log.Error(Logfornet.LogMessage(model.CustomerName, "CreateCustomer", errors.ToArray(), ""));
                    c.Status = Status.BadRequest.ToString();
                    c.Result = BadRequest();
                    return(c);
                }
                if (string.IsNullOrEmpty(model.CompanyLogo))
                {
                    Log.Error(Logfornet.LogMessage(model.CustomerName, "CreateCustomer", "Please upload company logo", ""));
                    c.Status = Status.BadRequest.ToString();
                    c.Result = "Please upload companylogo";
                    return(c);
                }
                if (User.IsInRole(Roles.SuperAdmin) || User.IsInRole(Roles.PortalAdmin))
                {
                    Customer Cus = new Customer();
                    var      res = Cus.AddCustomer(model, ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value);
                    if (res != null)
                    {
                        Log.Info(Logfornet.LogMessage(model.CustomerName, "CreateCustomer", ErrorMessages.Success, ""));
                        c.Status = Status.Success.ToString();
                        c.Result = res;
                        return(c);
                    }
                    else
                    {
                        Log.Warn(Logfornet.LogMessage(model.CustomerName, "CreateCustomer", ErrorMessages.AlreadyExists, ""));
                        c.Status = Status.Fail.ToString();
                        c.Result = "Aready Exists";
                        return(c);
                    }
                }
                else
                {
                    Log.Error(Logfornet.LogMessage(model.CustomerName, "CreateCustomer", ErrorMessages.NoAccessDenied, ""));
                    c.Status = Status.NoAccess.ToString();
                    c.Result = "No Access";
                    return(c);
                }
            }
            catch (TFSqlException ex)
            {
                Log.Error(Logfornet.LogMessage(model.CustomerName, "CreateCustomer", ex.Message, ex.StackTrace));
                c.Status     = ExceptionStatus.SqlException.ToString();
                c.StatusCode = (int)ExceptionStatus.SqlException;
                c.Result     = ex.InnerException;
                return(c);
            }
        }
        // [Authorize(Roles = "Super Admin,Portal Admin,Account Admin")]
        public StatusResult EditCustomer(int CompanyId)
        {
            StatusResult c = new Models.StatusResult();

            try
            {
                if (!ModelState.IsValid)
                {
                    var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => x.Value.Errors.Select(y => y.ErrorMessage)).ToList();
                    Log.Error(Logfornet.LogMessage(CompanyId, "EditCustomer", errors.ToArray(), ""));
                    c.Status = Status.BadRequest.ToString();
                    c.Result = BadRequest();
                    return(c);
                }
                if (User.IsInRole(Roles.SuperAdmin) || User.IsInRole(Roles.PortalAdmin) || User.IsInRole(Roles.AccountAdmin))
                {
                    Customer Cus    = new Customer();
                    string   UserId = string.Empty;
                    if (User.IsInRole(Roles.AccountAdmin))
                    {
                        UserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
                    }
                    var res = Cus.EditCustomer(CompanyId, UserId);
                    if (res != null)
                    {
                        Log.Info(Logfornet.LogMessage(CompanyId, "EditCustomer", ErrorMessages.Success, ""));
                        c.Status = Status.Success.ToString();
                        c.Result = res;
                        return(c);
                    }
                    else
                    {
                        Log.Warn(Logfornet.LogMessage(CompanyId, "UpdateCustomer", ErrorMessages.NoResults, ""));
                        c.Status = Status.Fail.ToString();
                        c.Result = "No Customer found";
                        return(c);
                    }
                }
                else
                {
                    Log.Error(Logfornet.LogMessage(CompanyId, "EditCustomer", ErrorMessages.NoAccessDenied, ""));
                    c.Status = Status.NoAccess.ToString();
                    c.Result = "No Access";
                    return(c);
                }
            }
            catch (Exception ex)
            {
                Log.Error(Logfornet.LogMessage(CompanyId, "EditCustomer", ex.Message, ex.StackTrace));
                c.Status = Status.InternalServerError.ToString();
                c.Result = ex.InnerException;
                return(c);
            }
        }
        public async Task <StatusResult> UploadInspectionXml(Inspection model)
        {
            StatusResult c = new StatusResult();

            try
            {
                if (!ModelState.IsValid)
                {
                    var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => x.Value.Errors.Select(y => y.ErrorMessage)).ToList();
                    Log.Error(Logfornet.LogMessage(model.CompanyId, "UploadInspectionXml", errors.ToArray(), ""));

                    c.Status = Status.BadRequest.ToString();
                    c.Result = BadRequest();
                    return(c);
                }
                if (User.IsInRole(Roles.SuperAdmin) || User.IsInRole(Roles.PortalAdmin) || User.IsInRole(Roles.AccountAdmin))
                {
                    InspectionConfig InspectionConfig = new InspectionConfig();
                    string           UserID           = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
                    var res = await InspectionConfig.UploadRoadsideInspection(model, UserID);

                    if (res.Contains("Successfully"))
                    {
                        Log.Info(Logfornet.LogMessage(model.CompanyId, "UploadInspectionXml", ErrorMessages.Success, ""));
                        c.Status = Status.Success.ToString();
                        c.Result = res;
                        return(c);
                    }
                    else
                    {
                        Log.Warn(Logfornet.LogMessage(model.CompanyId, "UploadInspectionXml", ErrorMessages.NoResults, ""));
                        c.Status = Status.Fail.ToString();
                        c.Result = res;
                        return(c);
                    }
                }
                else
                {
                    Log.Warn(Logfornet.LogMessage(model.CompanyId, "UploadInspectionXml", ErrorMessages.NoAccessDenied, ""));
                    c.Status = Status.NoAccess.ToString();
                    c.Result = "No Access";
                    return(c);
                }
            }
            catch (Exception ex)
            {
                Log.Error(Logfornet.LogMessage(model.CompanyId, "UploadInspectionXml", ex.Message, ex.StackTrace));
                c.Status     = ExceptionStatus.SqlException.ToString();
                c.StatusCode = (int)ExceptionStatus.SqlException;
                c.Result     = ex.InnerException;
                return(c);
            }
        }
        public async Task <StatusResult> GetInspectionByDate(InspectionDriver inspection)
        {
            StatusResult c = new StatusResult();

            try
            {
                if (!ModelState.IsValid)
                {
                    var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => x.Value.Errors.Select(y => y.ErrorMessage)).ToList();
                    Log.Error(Logfornet.LogMessage(inspection.CompanyId, "GetInspectionByDate", errors.ToArray(), ""));

                    c.Status = Status.BadRequest.ToString();
                    c.Result = BadRequest();
                    return(c);
                }
                if (User.IsInRole(Roles.SuperAdmin) || User.IsInRole(Roles.PortalAdmin) || User.IsInRole(Roles.AccountAdmin))
                {
                    InspectionConfig InspectionConfig = new InspectionConfig();
                    var res = await InspectionConfig.GetInspectionByDate(inspection.CompanyId, inspection.InspectionDate);

                    if (res != null)
                    {
                        Log.Info(Logfornet.LogMessage(inspection.CompanyId, "GetInspectionByDate", ErrorMessages.Success, ""));
                        c.Status = Status.Success.ToString();
                        c.Result = res;
                        return(c);
                    }
                    else
                    {
                        Log.Warn(Logfornet.LogMessage(inspection.CompanyId, "GetInspectionByDate", ErrorMessages.NoResults, ""));
                        c.Status = Status.Fail.ToString();
                        c.Result = "Company is not active";
                        return(c);
                    }
                }
                else
                {
                    Log.Warn(Logfornet.LogMessage(inspection.CompanyId, "GetInspectionByDate", ErrorMessages.NoAccessDenied, ""));
                    c.Status = Status.NoAccess.ToString();
                    c.Result = "No Access";
                    return(c);
                }
            }
            catch (Exception ex)
            {
                Log.Error(Logfornet.LogMessage(inspection.CompanyId, "GetInspectionByDate", ex.Message, ex.StackTrace));
                c.Status     = ExceptionStatus.SqlException.ToString();
                c.StatusCode = (int)ExceptionStatus.SqlException;
                c.Result     = ex.InnerException;
                return(c);
            }
        }
Example #7
0
        public async Task <StatusResult> UploadBulkDrivers(UploadDrivers model)
        {
            StatusResult c = new StatusResult();

            try
            {
                if (!ModelState.IsValid)
                {
                    var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => x.Value.Errors.Select(y => y.ErrorMessage)).ToList();
                    Log.Error(Logfornet.LogMessage(model.CompanyID, "UploadBulkDrivers", errors.ToArray(), ""));
                    c.Status = Status.BadRequest.ToString();
                    c.Result = BadRequest();
                    return(c);
                }
                if (User.IsInRole(Roles.SuperAdmin) || User.IsInRole(Roles.PortalAdmin) || User.IsInRole(Roles.AccountAdmin))
                {
                    DriverConfig DriverConfig = new DriverConfig();
                    string       UserID       = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
                    var          res          = await DriverConfig.UploadDrivers(model, UserID);

                    if (res != null)
                    {
                        Log.Error(Logfornet.LogMessage(model.CompanyID, "UploadBulkDrivers", "Please upload company logo", ""));
                        c.Status = Status.Success.ToString();
                        c.Result = res.DriverData;
                        return(c);
                    }
                    else
                    {
                        Log.Warn(Logfornet.LogMessage(model.CompanyID, "UploadBulkDrivers", ErrorMessages.AlreadyExists, ""));
                        c.Status = Status.Fail.ToString();
                        c.Result = "Please upload standard file.";
                        return(c);
                    }
                }
                else
                {
                    Log.Warn(Logfornet.LogMessage(model.CompanyID, "UploadBulkDrivers", ErrorMessages.NoAccessDenied, ""));
                    c.Status = Status.NoAccess.ToString();
                    c.Result = "No Access";
                    return(c);
                }
            }
            catch (Exception ex)
            {
                Log.Error(Logfornet.LogMessage(model.CompanyID, "UploadBulkDrivers", ex.Message, ex.StackTrace));
                c.Status     = ExceptionStatus.SqlException.ToString();
                c.StatusCode = (int)ExceptionStatus.SqlException;
                c.Result     = "Please upload standard file.";
                return(c);
            }
        }
        public StatusResult UpdateCustomer(CustomerProfile model)
        {
            StatusResult c = new Models.StatusResult();

            try
            {
                if (!ModelState.IsValid)
                {
                    var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => x.Value.Errors.Select(y => y.ErrorMessage)).ToList();
                    Log.Error(Logfornet.LogMessage(model.CustomerName, "UpdateCustomer", errors.ToArray(), ""));
                    c.Status = Status.BadRequest.ToString();
                    c.Result = BadRequest();
                    return(c);
                }
                if (User.IsInRole(Roles.SuperAdmin) || User.IsInRole(Roles.PortalAdmin) || User.IsInRole(Roles.AccountAdmin))
                {
                    Customer      Cus       = new Customer();
                    List <string> RoleNames = ClaimsPrincipal.Current.FindAll(ClaimTypes.Role).Select(x => x.Value).ToList();
                    var           res       = Cus.UpdateCustomer(model, String.Join(",", RoleNames.ToArray()), ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value);
                    if (res == null)
                    {
                        Log.Warn(Logfornet.LogMessage(model.CustomerName, "UpdateCustomer", ErrorMessages.AlreadyExists, ""));
                        c.Status = Status.Fail.ToString();
                        c.Result = "Already Exists";
                        return(c);
                    }
                    else
                    {
                        Log.Info(Logfornet.LogMessage(model.CustomerName, "UpdateCustomer", ErrorMessages.Success, ""));
                        c.Status = Status.Success.ToString();
                        c.Result = res;
                        return(c);
                    }
                }
                else
                {
                    Log.Error(Logfornet.LogMessage(model.CustomerName, "UpdateCustomer", ErrorMessages.NoAccessDenied, ""));
                    c.Status = Status.NoAccess.ToString();
                    c.Result = "No Access";
                    return(c);
                }
            }
            catch (Exception ex)
            {
                Log.Error(Logfornet.LogMessage(model.CustomerName, "UpdateCustomer", ex.Message, ex.StackTrace));
                c.Status = Status.InternalServerError.ToString();
                c.Result = ex.InnerException;
                return(c);
            }
        }
        // [Authorize(Roles = "Super Admin,Portal Admin")]
        public StatusResult CheckCustomerExists(string CustomerName)
        {
            StatusResult c = new Models.StatusResult();

            try
            {
                if (!ModelState.IsValid)
                {
                    c.Status = Status.BadRequest.ToString();
                    c.Result = BadRequest();
                    return(c);
                }
                if (User.IsInRole(Roles.SuperAdmin) || User.IsInRole(Roles.PortalAdmin) || User.IsInRole(Roles.AccountAdmin))
                {
                    Customer Cus = new Customer();
                    var      res = Cus.CheckCustomerExists(CustomerName);
                    if (res == null)
                    {
                        Log.Info(Logfornet.LogMessage(CustomerName, "CustomerExists", ErrorMessages.Success, ""));
                        c.Status = Status.Success.ToString();
                        c.Result = res;
                        return(c);
                    }
                    else
                    {
                        Log.Warn(Logfornet.LogMessage(CustomerName, "CustomerExists", ErrorMessages.NoResults, ""));
                        c.Status = Status.NoResult.ToString();
                        c.Result = "Company not avilable or not active";
                        return(c);
                    }
                }
                else
                {
                    Log.Error(Logfornet.LogMessage(CustomerName, "CustomerExists", ErrorMessages.NoAccessDenied, ""));
                    c.Status = Status.NoAccess.ToString();
                    c.Result = "No Access";
                    return(c);
                }
            }
            catch (Exception ex)
            {
                Log.Error(Logfornet.LogMessage(CustomerName, "CustomerExists", ex.Message, ex.StackTrace));
                c.Status = Status.InternalServerError.ToString();
                c.Result = ex.InnerException;
                return(c);
            }
        }
        // [Authorize(Roles = "Super Admin,Portal Admin")]
        public StatusResult GetCustomerProfileByUserID()
        {
            StatusResult c = new Models.StatusResult();

            try
            {
                if (!ModelState.IsValid)
                {
                    c.Status = Status.BadRequest.ToString();
                    c.Result = BadRequest();
                    return(c);
                }
                string   UserID = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
                Customer Cus    = new Customer();
                List <CustomerProfileDTO> cusdetails = new List <CustomerProfileDTO>();
                if (User.IsInRole(Roles.AccountAdmin))
                {
                    cusdetails = Cus.GetCustomerProfileByUserID(UserID);
                }
                if (User.IsInRole(Roles.SuperAdmin) || User.IsInRole(Roles.PortalAdmin))
                {
                    cusdetails = Cus.GetCustomerProfileBySuperPortalAdmin(UserID);
                }
                if (cusdetails == null)
                {
                    Log.Error(Logfornet.LogMessage(UserID, "GetCustomersByUserid", ErrorMessages.NoAccessDenied, ""));
                    c.Status = Status.NoAccess.ToString();
                    c.Result = "No Access";
                    return(c);
                }
                else
                {
                    Log.Info(Logfornet.LogMessage(UserID, "GetCustomerByUserID", ErrorMessages.Success, ""));
                    c.Status = Status.Success.ToString();
                    c.Result = cusdetails;
                    return(c);
                }
            }
            catch (Exception ex)
            {
                Log.Error(Logfornet.LogMessage(ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value, "GetCustomersByUser", ex.Message, ex.StackTrace));
                c.Status = Status.InternalServerError.ToString();
                c.Result = ex.InnerException;
                return(c);
            }
        }
        // [Authorize(Roles = "Super Admin,Portal Admin")]
        public StatusResult Delete(int CompanyID)
        {
            StatusResult c = new Models.StatusResult();

            try
            {
                if (!ModelState.IsValid)
                {
                    c.Status = Status.BadRequest.ToString();
                    c.Result = BadRequest();
                    return(c);
                }
                if (User.IsInRole(Roles.SuperAdmin) || User.IsInRole(Roles.PortalAdmin))
                {
                    Customer Cus = new Customer();
                    if (Cus.DeleteCustomer(CompanyID, ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value))
                    {
                        Log.Info(Logfornet.LogMessage(CompanyID, "DeleteCustomer", ErrorMessages.Success, ""));
                        c.Status = Status.Success.ToString();
                        c.Result = true;
                        return(c);
                    }
                    else
                    {
                        Log.Warn(Logfornet.LogMessage(CompanyID, "DeleteCustomer", ErrorMessages.NoResults, ""));
                        c.Status = Status.Fail.ToString();
                        c.Result = "Not found";
                        return(c);
                    }
                }
                else
                {
                    Log.Error(Logfornet.LogMessage(CompanyID, "DeleteCustomer", ErrorMessages.NoAccessDenied, ""));
                    c.Status = Status.NoAccess.ToString();
                    c.Result = "No access";
                    return(c);
                }
            }
            catch (Exception ex)
            {
                Log.Error(Logfornet.LogMessage(CompanyID, "DeleteCustomer", ex.Message, ex.StackTrace));
                c.Status = Status.InternalServerError.ToString();
                c.Result = ex.InnerException;
                return(c);
            }
        }
        public StatusResult InsertInspectionEntry(ManualRSI Rsi)
        {
            StatusResult c = new StatusResult();

            try
            {
                if (!ModelState.IsValid)
                {
                    var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => x.Value.Errors.Select(y => y.ErrorMessage)).ToList();
                    Log.Error(Logfornet.LogMessage(Rsi.CompanyID, "InsertInspectionEntry", errors.ToArray(), ""));

                    c.Status = Status.BadRequest.ToString();
                    c.Result = BadRequest();
                    return(c);
                }
                if (User.IsInRole(Roles.SuperAdmin) || User.IsInRole(Roles.PortalAdmin) || User.IsInRole(Roles.AccountAdmin))
                {
                    InspectionConfig InspectionConfig = new InspectionConfig();
                    Rsi.CreatedBy  = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
                    Rsi.ModifiedBy = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
                    Rsi.CreatedOn  = DateTime.Now;
                    Rsi.ModifiedOn = DateTime.Now;
                    var res = InspectionConfig.InsertInspectionEntry(Rsi);
                    Log.Info(Logfornet.LogMessage(Rsi.CompanyID, "InsertInspectionEntry", ErrorMessages.Success, ""));
                    c.Status = Status.Success.ToString();
                    c.Result = res;
                    return(c);
                }
                else
                {
                    Log.Warn(Logfornet.LogMessage(Rsi.CompanyID, "InsertInspectionEntry", ErrorMessages.NoAccessDenied, ""));
                    c.Status = Status.NoAccess.ToString();
                    c.Result = "No Access";
                    return(c);
                }
            }
            catch (Exception ex)
            {
                Log.Error(Logfornet.LogMessage(Rsi.CompanyID, "InsertInspectionEntry", ex.Message, ex.StackTrace));
                c.Status     = ExceptionStatus.SqlException.ToString();
                c.StatusCode = (int)ExceptionStatus.SqlException;
                c.Result     = ex.InnerException;
                return(c);
            }
        }
        public async Task <ActionResult> SaveRegisterUser(RegisterBindingModel model)
        {
            try
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userData.AccessToken);
                HttpResponseMessage responseMessage = await client.PostAsJsonAsync(_url + "Account/Register", model);

                if (responseMessage.IsSuccessStatusCode)
                {
                    var          result       = responseMessage.Content.ReadAsStringAsync().Result;
                    StatusResult statusResult = JsonConvert.DeserializeObject <StatusResult>(result);
                    if (statusResult.Status.Equals(Status.Success.ToString()))
                    {
                        return(Json(statusResult.Status, JsonRequestBehavior.AllowGet));
                    }
                    else if (statusResult.Status.Equals(Status.Fail.ToString()))
                    {
                        return(Json(statusResult.Result.ToString().Replace(",", "</br>"), JsonRequestBehavior.AllowGet));
                    }
                }
                return(Json("Error", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Log.Info(Logfornet.LogMessage(model.FirstName, "SaveRegisterUser", ex.Message, ""));
                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
            #region Default Code
            //var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
            //var result = await UserManager.CreateAsync(user, model.Password);
            //if (result.Succeeded)
            //{
            //    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

            //    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
            //    // Send an email with this link
            //    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
            //    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
            //    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

            //    return RedirectToAction("Index", "Home");
            //}
            //AddErrors(result);
            #endregion
        }
        public async Task <StatusResult> UploadInspectionDocumnets(List <BlobUploadModel> documentData)
        {
            StatusResult c         = new StatusResult();
            var          CompanyId = documentData.FirstOrDefault().CompanyId;

            try
            {
                if (!ModelState.IsValid)
                {
                    var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => x.Value.Errors.Select(y => y.ErrorMessage)).ToList();
                    Log.Error(Logfornet.LogMessage(CompanyId, "UploadInspectionDocumnets", errors.ToArray(), ""));

                    c.Status = Status.BadRequest.ToString();
                    c.Result = BadRequest();
                    return(c);
                }
                if (User.IsInRole(Roles.SuperAdmin) || User.IsInRole(Roles.PortalAdmin) || User.IsInRole(Roles.AccountAdmin))
                {
                    InspectionConfig InspectionConfig = new InspectionConfig();
                    await InspectionConfig.UploadInspectionDocumnets(documentData, CompanyId);

                    Log.Info(Logfornet.LogMessage(CompanyId, "UploadInspectionDocumnets", ErrorMessages.Success, ""));
                    c.Status = Status.Success.ToString();
                    c.Result = "Inserted Successfully";
                    return(c);
                }
                else
                {
                    Log.Warn(Logfornet.LogMessage(CompanyId, "UploadInspectionDocumnets", ErrorMessages.NoAccessDenied, ""));
                    c.Status = Status.NoAccess.ToString();
                    c.Result = "No Access";
                    return(c);
                }
            }
            catch (Exception ex)
            {
                Log.Error(Logfornet.LogMessage(CompanyId, "UploadInspectionDocumnets", ex.Message, ex.StackTrace));
                c.Status     = ExceptionStatus.SqlException.ToString();
                c.StatusCode = (int)ExceptionStatus.SqlException;
                c.Result     = ex.InnerException;
                return(c);
            }
        }
        public async Task <ActionResult> EditUser(string UserId, string RoleName)
        {
            RegisterBindingModel rbModel = new RegisterBindingModel();

            try
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userData.AccessToken);
                HttpResponseMessage responseMessage = await client.PostAsJsonAsync(_url + "Account/EditUser/" + UserId, "");

                if (responseMessage.IsSuccessStatusCode)
                {
                    var          result       = responseMessage.Content.ReadAsStringAsync().Result;
                    StatusResult statusResult = JsonConvert.DeserializeObject <StatusResult>(result);
                    if (statusResult.Status.Equals(Status.Success.ToString()))
                    {
                        rbModel          = JsonConvert.DeserializeObject <RegisterBindingModel>(statusResult.Result.ToString());
                        ViewBag.RoleList = BindDropDownRoles();
                        Log.Info(Logfornet.LogMessage(UserId, "Login", ErrorMessages.Success, ""));
                        rbModel.RoleName = RoleName;
                        return(PartialView("_RegisterUserPartial", rbModel));
                    }
                    else
                    {
                        Log.Info(Logfornet.LogMessage(UserId, "EditUser", statusResult.Status, ""));
                        rbModel.ErrorMessage = statusResult.Status;
                    }
                }
                else
                {
                    Log.Info(Logfornet.LogMessage(UserId, "EditUser", responseMessage.StatusCode, ""));
                    rbModel.ErrorMessage = responseMessage.StatusCode.ToString();
                }
                return(PartialView("_RegisterUserPartial", rbModel));
            }
            catch (Exception ex)
            {
                Log.Info(Logfornet.LogMessage(UserId, "EditUser", ex.Message, ""));
                rbModel.ErrorMessage = ex.Message;
                return(PartialView("_RegisterUserPartial", rbModel));
            }
        }
Example #16
0
        public async Task <ActionResult> GetAllCustomer()
        {
            CustomerProfile objCprofile = new CustomerProfile();

            try
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userData.AccessToken);
                HttpResponseMessage responseMessage = await client.PostAsJsonAsync(_url + "Customer/GetCustomerProfileByUserID", "");

                var result = responseMessage.Content.ReadAsStringAsync().Result;
                statusResult = JsonConvert.DeserializeObject <StatusResult>(result);
                if (responseMessage.IsSuccessStatusCode)
                {
                    if (statusResult.Status.Equals(Status.Success.ToString()))
                    {
                        List <CustomerProfile> customerData = JsonConvert.DeserializeObject <List <CustomerProfile> >(statusResult.Result.ToString());
                        var jsonResult = Json(new { data = customerData }, JsonRequestBehavior.AllowGet);
                        jsonResult.MaxJsonLength = int.MaxValue;
                        return(jsonResult);
                    }
                    else
                    {
                        objCprofile.ExMessage = statusResult.Status;
                        Log.Error(Logfornet.LogMessage("", "GetAllCustomer", statusResult.Status, ""));
                    }
                }
                else
                {
                    objCprofile.ExMessage = responseMessage.StatusCode.ToString();
                    Log.Error(Logfornet.LogMessage("", "GetAllCustomer", responseMessage.StatusCode, ""));
                }
                return(Json(new { data = objCprofile }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                objCprofile.ExMessage = ex.Message;
                Log.Error(Logfornet.LogMessage("", "GetAllCustomer", ex.Message, ""));
                return(Json(new { data = objCprofile }, JsonRequestBehavior.AllowGet));
            }
        }
Example #17
0
        public async Task <ActionResult> CreateNewCustomer(CustomerProfile model)
        {
            CustomerProfile customerData = new CustomerProfile();

            try
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userData.AccessToken);
                HttpResponseMessage responseMessage = await client.PostAsJsonAsync(_url + "Customer/AddCustomer", model);

                var result = responseMessage.Content.ReadAsStringAsync().Result;
                statusResult = JsonConvert.DeserializeObject <StatusResult>(result);
                if (responseMessage.IsSuccessStatusCode)
                {
                    if (statusResult.Status.Equals(Status.Success.ToString()))
                    {
                        Log.Error(Logfornet.LogMessage("", "CreateNewCustomer", statusResult.Result, ""));
                        customerData = JsonConvert.DeserializeObject <CustomerProfile>(statusResult.Result.ToString());
                        return(Json(customerData, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        Log.Error(Logfornet.LogMessage("", "CreateNewCustomer", statusResult.Result, ""));
                        customerData.ExMessage = statusResult.Status;
                    }
                }
                else
                {
                    Log.Error(Logfornet.LogMessage("", "CreateNewCustomer", responseMessage.StatusCode, ""));
                    customerData.ExMessage = responseMessage.StatusCode.ToString();
                }
                return(Json(new { data = customerData }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                customerData.ExMessage = ex.Message;
                Log.Error(Logfornet.LogMessage("", "GetAllCustomer", ex.Message, ""));
                return(Json(new { data = customerData }, JsonRequestBehavior.AllowGet));
            }
        }
Example #18
0
        public async Task <ActionResult> EditCustomer(int CompanyId)
        {
            CustomerProfile customerData = new CustomerProfile();

            try
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userData.AccessToken);
                HttpResponseMessage responseMessage = await client.PostAsJsonAsync(_url + "Customer/EditCustomer/" + CompanyId, "");

                var result = responseMessage.Content.ReadAsStringAsync().Result;
                statusResult = JsonConvert.DeserializeObject <StatusResult>(result);
                if (responseMessage.IsSuccessStatusCode)
                {
                    if (statusResult.Status.Equals(Status.Success.ToString()))
                    {
                        customerData     = JsonConvert.DeserializeObject <CustomerProfile>(statusResult.Result.ToString());
                        ViewBag.UserRole = TempData["UserRole"];
                        TempData.Keep();
                    }
                    else
                    {
                        customerData.ExMessage = statusResult.Status;
                        Log.Error(Logfornet.LogMessage(CompanyId, "EditCustomer", statusResult.Result, statusResult.Status));
                    }
                }
                else
                {
                    customerData.ExMessage = responseMessage.StatusCode.ToString();
                }
                return(View("CreateCustomer", customerData));
            }
            catch (Exception ex)
            {
                customerData.ExMessage = ex.Message;
                return(View("CreateCustomer", customerData));
            }
        }
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            try
            {
                #region captch validate
                //var captchaResponse = ValidateCaptha();
                //if (!captchaResponse.Success)
                //{
                //    if (captchaResponse.ErrorCodes.Count <= 0) return View();

                //    var error = captchaResponse.ErrorCodes[0].ToLower();
                //    switch (error)
                //    {
                //        case ("missing-input-secret"):
                //            ViewBag.CaptchaErrorMessage = "The secret parameter is missing.";
                //            break;

                //        case ("invalid-input-secret"):
                //            ViewBag.CaptchaErrorMessage = "The secret parameter is invalid or malformed.";
                //            break;

                //        case ("missing-input-response"):
                //            ViewBag.CaptchaErrorMessage = "Please select the captcha";
                //            break;
                //        case ("invalid-input-response"):
                //            ViewBag.CaptchaErrorMessage = "The response parameter is invalid or malformed.";
                //            break;

                //        default:
                //            ViewBag.CaptchaErrorMessage = "Error occured. Please try again";
                //            break;
                //    }
                //}
                //else
                //{
                #endregion
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                HttpResponseMessage responseMessage = await client.PostAsJsonAsync(_url + "Account/Login", model);

                if (responseMessage.IsSuccessStatusCode)
                {
                    var          result       = responseMessage.Content.ReadAsStringAsync().Result;
                    StatusResult statusResult = JsonConvert.DeserializeObject <StatusResult>(result);
                    if (statusResult.Status == Status.Success.ToString())
                    {
                        Log.Info(Logfornet.LogMessage(model.Email, "Login", ErrorMessages.Success, ""));
                        UserModel obj = JsonConvert.DeserializeObject <UserModel>(statusResult.Result.ToString());
                        Session["UserData"] = obj;
                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        Log.Info(Logfornet.LogMessage(model.Email, "Login", statusResult.Status, ""));
                        model.ErrorMessage = "Wrong username or password";
                        return(View(model));
                    }
                }
                else
                {
                    Log.Info(Logfornet.LogMessage(model.Email, "Login", responseMessage.StatusCode, ""));
                    model.ErrorMessage = responseMessage.StatusCode.ToString();
                    return(View(model));
                }
                //}
                //return View(model);
            }
            catch (Exception ex)
            {
                Log.Info(Logfornet.LogMessage(model.Email, "Login", ex.Message, ""));
                model.ErrorMessage = ex.Message;
                return(View(model));
            }
            #region default code
            //// This doesn't count login failures towards account lockout
            //// To enable password failures to trigger account lockout, change to shouldLockout: true
            //var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
            //switch (result)
            //{
            //    case SignInStatus.Success:
            //        return RedirectToLocal(returnUrl);
            //    case SignInStatus.LockedOut:
            //        return View("Lockout");
            //    case SignInStatus.RequiresVerification:
            //        return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
            //    case SignInStatus.Failure:
            //    default:
            //        ModelState.AddModelError("", "Invalid login attempt.");
            //        return View(model);
            //}
            #endregion
        }