示例#1
0
        public static ClientRegRespObj AddClient(RegClientObj regObj, string username)
        {
            var response = new ClientRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage(),
                },
            };

            try
            {
                var apiResponse = new APIHelper(APIEndpoints.ADD_CLIENT_ENDPOINT, username, Method.POST).ProcessAPI <RegClientObj, ClientRegRespObj>(regObj, out var msg);
                if (msg.Code == 0 && string.IsNullOrEmpty(msg.TechMessage) && string.IsNullOrEmpty(msg.Message))
                {
                    return(apiResponse);
                }

                response.Status.Message.FriendlyMessage  = msg.Message;
                response.Status.Message.TechnicalMessage = msg.TechMessage;
                return(response);
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.GetBaseException().Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                return(response);
            }
        }
示例#2
0
        public JsonResult ProcessAddClientRequest(RegClientObj model)
        {
            try
            {
                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();

                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                if (model == null)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                if (string.IsNullOrEmpty(model.ClientName) || model.ClientName.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Client Name" }));
                }
                if (string.IsNullOrEmpty(model.Address) || model.Address.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Address " }));
                }
                if (string.IsNullOrEmpty(model.MobileNumber) || model.MobileNumber.Length < 7 || model.MobileNumber.Length > 15)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Mobile Number " }));
                }

                model.AdminUserId = userData.UserId;

                var previousClientList =
                    (List <ClientObj>)Session["_ClientList_"];
                if (previousClientList != null)
                {
                    if (previousClientList.Count(x =>
                                                 x.ClientName.ToLower().Trim().ToStandardHash() == model.ClientName.ToLower().Trim().ToStandardHash()) > 0)
                    {
                        return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Client  Already Exist!" }));
                    }
                }


                var response = ClientService.AddClient(model, userData.Username);
                if (response?.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }

                if (!response.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.TechnicalMessage) ? "Process Failed! Unable to add nomination Source" : response.Status.Message.TechnicalMessage }));
                }

                var searchObj = new ClientSearchObj
                {
                    AdminUserId = userData.UserId,
                    ClientId    = 0,
                    Status      = -2
                };

                var retVal = ClientService.LoadClients(searchObj, userData.Username);
                if (retVal?.Status != null && retVal.Clients != null)
                {
                    var clients = retVal.Clients.OrderBy(m => m.ClientId).ToList();
                    Session["_ClientList_"] = clients;
                }

                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }