Beispiel #1
0
        public async Task <UserModel> AddAsync(UserModel model)
        {
            var entity   = _mapper.Map <User>(model);
            var merchant = new Merchant
            {
                MerchantName   = model.MerchantName,
                Active         = true,
                CreatedAt      = DateTime.Now,
                MerchantTypeID = 1,
                WebsiteUrl     = model.WebsiteUrl,
            };

            _unitOfWork.MerchantRepository.Add(merchant);
            _unitOfWork.UsersRepository.Add(entity);
            await _unitOfWork.SaveAsync();

            var role = new MerchantUser
            {
                Active     = true,
                CreatedAt  = DateTime.Now,
                MerchantID = merchant.ID,
                UserID     = entity.ID,
                RoleID     = 1
            };

            _unitOfWork.MerchantUserRepository.Add(role);
            await _unitOfWork.SaveAsync();

            return(_mapper.Map <UserModel>(entity));
        }
Beispiel #2
0
        public async Task UpdatePasswordAsync(MerchantUser account)
        {
            var filter = Builders <MerchantUser> .Filter.Eq(x => x.Phone, account.Phone);

            var update = Builders <MerchantUser> .Update.Set(x => x.Password, account.Password);

            var result = await _mongoDbContext.MerchantUsers.UpdateOneAsync(filter, update);
        }
        public async Task <MerchantUserDto> Handle(CreateMerchantUserCommand request, CancellationToken cancellationToken)
        {
            var accountUser = MerchantUser.CreateRegisteredByMerchant(request.MerchantCode, request.MerchantName, request.FirstName, request.LastName,
                                                                      request.Password.AsMd5(),
                                                                      request.Email, request.Phone, request.IsActive, request.Claims, _merchantUserUniquenessChecker);

            await _merchantUserRepository.CreateAsync(accountUser);

            return(_mapper.Map <MerchantUserDto>(accountUser));
        }
Beispiel #4
0
        public async Task <UserDto> Authenticate(string EmailOrPhone, string password, int expiryInDay)
        {
            var isEmail = EmailOrPhone.IsEmail();
            var user    = new MerchantUser();

            if (isEmail)
            {
                user = await _userRepository.GetWithEmailAsync(EmailOrPhone, password.AsMd5());
            }
            else
            {
                user = await _userRepository.GetWithPhoneAsync(EmailOrPhone, password.AsMd5());
            }

            // return null if user not found
            if (user == null)
            {
                throw new MerchantUserNotFoundException();
            }

            // authentication successful so generate jwt token
            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = Encoding.ASCII.GetBytes(_secretKey);
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new[]
                {
                    new Claim(ClaimTypes.MobilePhone, user.Phone),
                    new Claim(ClaimTypes.Email, user.Email),
                    new Claim(ClaimTypes.Name, user.FirstName),
                    new Claim(ClaimTypes.Surname, user.LastName),
                    new Claim(nameof(user.MerchantCode), user.MerchantCode.ToString()),
                    new Claim(nameof(user.MerchantName), user.MerchantName)
                }),
                Expires            = DateTime.UtcNow.AddDays(100),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };
            var token = tokenHandler.CreateToken(tokenDescriptor);

            var userDto = new UserDto
            {
                Token     = $"Bearer {tokenHandler.WriteToken(token)}",
                Claims    = user.Claims,
                Email     = user.Email,
                Phone     = user.Phone,
                FirstName = user.FirstName,
                LastName  = user.LastName
            };

            return(userDto);
        }
Beispiel #5
0
        public async Task <Unit> Handle(RegisterMerchantCommand request, CancellationToken cancellationToken)
        {
            var merchant     = Merchant.Register(request.MerchantName);
            var merchantUser = MerchantUser.CreateRegisteredOnNewRegister(merchant.Code, merchant.Name, request.FirstName, request.LastName, request.Email,
                                                                          request.Phone, request.Password.AsMd5(), new List <string> {
                "account-admin"
            }, _merchantUserUniquenessChecker);

            await _merchantUserRepository.CreateAsync(merchantUser);

            await _merchantRepository.CreateAsync(merchant);

            return(Unit.Task.Result);
        }
Beispiel #6
0
        //[HttpPost]
        //[Route("ChangePasswordForClient")]
        //public object ChangePasswordForClient([FromBody]ChangePasswordModel model)
        //{
        //    try
        //    {
        //        MerchantUser userDetails = merchantUsersService.SingleOrDefault(model.DisbursementUserId, new MerchantUser());
        //        if (validatePasswordForClient(userDetails, model))
        //        {
        //            return ChangePasswordForClient(userDetails, model);
        //        }

        //        return "Old Password is Invalid";

        //    }
        //    catch (Exception ex)
        //    {
        //        return errorLogService.InsertToErrorLog(ex, MethodBase.GetCurrentMethod().Name, Request.Headers["UserInfo"].ToString());

        //    }
        //}
        private object ChangePasswordForClient(MerchantUser userDetails, ChangePasswordModel model)
        {
            try
            {
                StringBuilderService stringBuilderService = new StringBuilderService();
                userDetails.Md5Password   = stringBuilderService.GenerateMD5Hash(model.NewPassword);
                userDetails.Sha1Password  = stringBuilderService.GenerateSha1Hash(model.NewPassword);
                userDetails.SecurityStamp = Guid.NewGuid().ToString();
                userDetails.Pstatus       = "Y";
                return(merchantUsersService.Save(userDetails));
            }
            catch (Exception ex)
            {
                return(errorLogService.InsertToErrorLog(ex, MethodBase.GetCurrentMethod().Name, Request.Headers["UserInfo"].ToString()));
            }
        }
        public object ChangePasswordForClient([FromBody] ChangePasswordModel model)
        {
            try
            {
                MerchantUser userDetails = merchantUsersService.SingleOrDefault(model.ApplicationUserId, new MerchantUser());
                if (validatePasswordForClient(userDetails, model))
                {
                    return(ChangePasswordForClient(userDetails, model));
                }

                return("Old Password is Invalid");
            }
            catch (Exception ex)
            {
                return(errorLogService.InsertToErrorLog(ex, MethodBase.GetCurrentMethod().Name, Request.Headers["UserInfo"].ToString()));
            }
        }
Beispiel #8
0
        private MerchantUser generateSecuredCredentials(MerchantUser model)
        {
            try
            {
                StringBuilderService stringBuilderService = new StringBuilderService();
                model.PlainPassword = model.PlainPassword;
                model.Md5Password   = stringBuilderService.GenerateMD5Hash(model.PlainPassword);
                model.Sha1Password  = stringBuilderService.GenerateSha1Hash(model.PlainPassword);
                model.SecurityStamp = Guid.NewGuid().ToString();

                return(model);
            }
            catch (Exception ex)
            {
                errorLogService.InsertToErrorLog(ex, MethodBase.GetCurrentMethod().Name, Request.Headers["UserInfo"].ToString());
                throw;
            }
        }
Beispiel #9
0
        private bool validatePasswordForClient(MerchantUser userDetails, ChangePasswordModel model)
        {
            try
            {
                StringBuilderService stringBuilderService = new StringBuilderService();

                if (userDetails.Sha1Password == stringBuilderService.GenerateSha1Hash(model.OldPassword))
                {
                    return(true);
                }

                return(false);
            }
            catch (Exception ex)
            {
                errorLogService.InsertToErrorLog(ex, MethodBase.GetCurrentMethod().Name, Request.Headers["UserInfo"].ToString());
                throw;
            }
        }
Beispiel #10
0
        public HttpResponseMessage Post(FormDataCollection form)
        {
            var model  = new MerchantUser();
            var values = JsonConvert.DeserializeObject <IDictionary>(form.Get("values"));

            PopulateModel(model, values);

            Validate(model);
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, GetFullErrorMessage(ModelState)));
            }

            var result = _context.MerchantUsers.Add(model);

            _context.SaveChanges();

            return(Request.CreateResponse(HttpStatusCode.Created, result.id));
        }
Beispiel #11
0
        public object SaveMerchantUser(bool isEditMode, string evnt, [FromBody] MerchantUser model)
        {
            try
            {
                if (model.Id != 0)
                {
                    if (string.IsNullOrEmpty(model.PlainPassword))
                    {
                        return(_MerchantUserService.Update(model));
                    }
                    else
                    {
                        model = generateSecuredCredentials(model);
                        _MerchantUserService.Update(model);
                        return(HttpStatusCode.OK);
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(model.MobileNo))
                    {
                        model = generateSecuredCredentials(model);
                        model = _MerchantUserService.Add(model);
                    }
                    else
                    {
                        dynamic reginfoModel = _MerchantUserService.GetRegInfoByMphone(model.MobileNo);
                        model.Name       = reginfoModel.NAME;
                        model.BranchCode = reginfoModel.BRANCH_CODE;
                        model            = generateSecuredCredentials(model);
                        model            = _MerchantUserService.Add(model);
                    }

                    if (!string.IsNullOrEmpty(model.MobileNo))
                    {
                        string messagePrefix = ", Your Account Has been Created on OK Wallet Admin Application. Your username is " + model.MobileNo + " and password is " + model.PlainPassword;

                        MessageModel messageModel = new MessageModel()
                        {
                            Mphone      = model.MobileNo,
                            MessageId   = "999",
                            MessageBody = "Dear " + model.Name + messagePrefix + ". Thank you."
                        };

                        MessageService messageService = new MessageService();
                        messageService.SendMessage(messageModel);

                        return(HttpStatusCode.OK);
                    }
                    else
                    {
                        return(HttpStatusCode.OK);
                    }
                }
            }
            catch (Exception ex)
            {
                errorLogService.InsertToErrorLog(ex, MethodBase.GetCurrentMethod().Name, Request.Headers["UserInfo"].ToString());
                return(HttpStatusCode.BadRequest);
            }
        }
Beispiel #12
0
        public static void Initialize(OperationsContext context)
        {
            if (!context.Database.EnsureCreated())
            {
                return; //db was already created or error occurred
            }

            var general = new MerchantType
            {
                Name        = "General Merchant",
                Description = "General Merchant Default Value",
                CreatedAt   = DateTime.UtcNow,
                Active      = true,
            };
            var online = new MerchantType
            {
                Name        = "Online Merchant",
                Description = "Online Merchant",
                CreatedAt   = DateTime.UtcNow,
                Active      = true,
            };
            var merchantTypes = new List <MerchantType>
            {
                general,
                online
            };

            foreach (var merchantType in merchantTypes)
            {
                context.MerchantTypes.Add(merchantType);
                context.SaveChanges();
            }

            var merchants = new List <Merchant>
            {
                new Merchant
                {
                    MerchantName   = "Rob's Merchant",
                    CreatedAt      = DateTime.UtcNow,
                    Active         = true,
                    WebsiteUrl     = string.Empty,
                    MerchantType   = general,
                    MerchantTypeID = general.ID
                },
                new Merchant
                {
                    MerchantName   = "Online Merchant",
                    CreatedAt      = DateTime.UtcNow,
                    Active         = true,
                    WebsiteUrl     = string.Empty,
                    MerchantType   = online,
                    MerchantTypeID = online.ID
                }
            };

            context.Merchants.AddRange(merchants);

            var itemTypes = new List <ItemType>
            {
                new ItemType
                {
                    Name        = "Merchandise",
                    Description = "Merchandise",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                },
                new ItemType
                {
                    Name        = "Discount",
                    Description = "Discount",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                }
            };


            foreach (var itemType in itemTypes)
            {
                context.ItemTypes.Add(itemType);
                context.SaveChanges();
            }


            var priceTypes = new List <PriceType>
            {
                new PriceType
                {
                    Name        = "Fixed",
                    Description = "Fixed Price",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                },
                new PriceType
                {
                    Name        = "Variable",
                    Description = "Variable Cost Price",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                }
            };

            foreach (var priceType in priceTypes)
            {
                context.PriceTypes.Add(priceType);
                context.SaveChanges();
            }

            var unitTypes = new List <UnitType>
            {
                new UnitType
                {
                    Name        = "Quantity",
                    Description = "Unit is measured in quantities",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                }
            };

            context.UnitTypes.AddRange(unitTypes);
            var owner = new Role
            {
                Name        = "Owner",
                Description = "Owner of the associated merchant",
                CreatedAt   = DateTime.UtcNow,
                Active      = true,
            };
            var onlineSignUp = new Role
            {
                Name        = "Online User",
                Description = "Online Sign up user",
                CreatedAt   = DateTime.UtcNow,
                Active      = true,
            };
            var roles = new List <Role>
            {
                owner,
                onlineSignUp
            };

            context.Roles.AddRange(roles);

            var orderStatusTypes = new List <OrderStatusType>
            {
                new OrderStatusType
                {
                    Name        = "Open",
                    Description = "Order needs to be paid for",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                },
                new OrderStatusType
                {
                    Name        = "Paid",
                    Description = "Order has been paid for",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                },
                new OrderStatusType
                {
                    Name        = "Partially Paid",
                    Description = "Order has been partially paid for",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                }
            };

            foreach (var orderStatusType in orderStatusTypes)
            {
                context.OrderStatusTypes.Add(orderStatusType);
                context.SaveChanges();
            }


            var paymentStatusTypes = new List <PaymentStatusType>
            {
                new PaymentStatusType
                {
                    Name        = "Pending",
                    Description = "Payment is pending",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                },
                new PaymentStatusType
                {
                    Name        = "Paid",
                    Description = "Payment is paid for",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                },
            };

            foreach (var paymentStatusType in paymentStatusTypes)
            {
                context.PaymentStatusTypes.Add(paymentStatusType);
                context.SaveChanges();
            }

            var paymentTypes = new List <PaymentType>
            {
                new PaymentType
                {
                    Name        = "Credit Card Manual",
                    Description = "Credit Card Manually Entered",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                },
                new PaymentType
                {
                    Name        = "Cash",
                    Description = "Cash",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                },
                new PaymentType
                {
                    Name        = "Check",
                    Description = "Check",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                },
            };

            foreach (var paymentType in paymentTypes)
            {
                context.PaymentTypes.Add(paymentType);
                context.SaveChanges();
            }

            var user = new User
            {
                Username   = "******",
                Email      = "*****@*****.**",
                Password   = "******",
                Active     = true,
                CreatedAt  = DateTime.Now,
                FirstName  = "Rob",
                MiddleName = "Wayne",
                LastName   = "Smitha",
            };

            context.Users.Add(user);

            var @namespace = "Domain.Entities";
            var entities   = AppDomain.CurrentDomain.GetAssemblies()
                             .SelectMany(t => t.GetTypes())
                             .Where(t => t.IsClass && t.Namespace == @namespace &&
                                    t.Name != "BaseModel");
            var entityList = new List <string>();


            var permissions = new List <Permission>();

            foreach (var entity in entities)
            {
                var contollerName = entity.Name;
                if (contollerName != "Blog")
                {
                    var lastLetter = contollerName.Substring(contollerName.Length - 1);
                    switch (lastLetter)
                    {
                    case "y":
                        contollerName = $"{entity.Name.TrimEnd('y')}ies";
                        break;

                    case "s":
                        contollerName = $"{entity.Name}es";
                        break;

                    default:
                        contollerName = $"{entity.Name}s";
                        break;
                    }
                }
                var access = new Permission
                {
                    Name        = $"Access{contollerName}",
                    Description = $"Can Access List {contollerName}",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                    Controller  = contollerName,
                    Action      = "Index"
                };
                permissions.Add(access);
                var create = new Permission
                {
                    Name        = $"Create{contollerName}",
                    Description = $"Can Create {contollerName}",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                    Controller  = contollerName,
                    Action      = "Create"
                };
                permissions.Add(create);
                var edit = new Permission
                {
                    Name        = $"Edit{contollerName}",
                    Description = $"Can Edit {contollerName}",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                    Controller  = contollerName,
                    Action      = "Edit"
                };
                permissions.Add(edit);
                var details = new Permission
                {
                    Name        = $"Details{contollerName}",
                    Description = $"Can Access Details {contollerName}",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                    Controller  = contollerName,
                    Action      = "Details"
                };
                permissions.Add(details);
                var delete = new Permission
                {
                    Name        = $"Delete{contollerName}",
                    Description = $"Can Delete {contollerName}",
                    CreatedAt   = DateTime.UtcNow,
                    Active      = true,
                    Controller  = contollerName,
                    Action      = "Delete"
                };
                permissions.Add(delete);
            }
            context.Permissions.AddRange(permissions);
            context.SaveChanges();

            var roleId          = roles.First(x => x.Name == "Owner").ID;
            var rolePermissions = new List <RolePermission>();

            foreach (var permission in permissions)
            {
                rolePermissions.Add(new RolePermission
                {
                    PermissionID = permission.ID,
                    RoleID       = roleId,
                    Active       = true,
                    CreatedAt    = DateTime.Now
                });
            }
            context.RolePermissions.AddRange(rolePermissions);
            context.SaveChanges();
            var merchant = merchants.FirstOrDefault();

            if (merchant != null)
            {
                var merchantUser = new MerchantUser
                {
                    UserID     = user.ID,
                    MerchantID = merchant.ID,
                    RoleID     = roleId,
                    Active     = true,
                    CreatedAt  = DateTime.Now
                };
                context.MerchantUsers.Add(merchantUser);
                context.SaveChanges();
            }

            var blogStatusTypes = new List <BlogStatusType>
            {
                new BlogStatusType
                {
                    Name        = "Drafted",
                    Description = "Drafted",
                    Active      = true,
                    CreatedAt   = DateTime.Now
                },
                new BlogStatusType
                {
                    Name        = "Published",
                    Description = "Published",
                    Active      = true,
                    CreatedAt   = DateTime.Now
                }
            };

            context.BlogStatusTypes.AddRange(blogStatusTypes);
            context.SaveChanges();
        }
Beispiel #13
0
 public async Task CreateAsync(MerchantUser user)
 {
     await _mongoDbContext.MerchantUsers.InsertOneAsync(user);
 }
Beispiel #14
0
        private void PopulateModel(MerchantUser model, IDictionary values)
        {
            string ID         = nameof(MerchantUser.id);
            string FIRST_NAME = nameof(MerchantUser.first_name);
            string LAST_NAME  = nameof(MerchantUser.last_name);
            string EMAIL      = nameof(MerchantUser.email);
            string CONTANT    = nameof(MerchantUser.contant);
            string PASSWORD   = nameof(MerchantUser.password);
            string TYPE       = nameof(MerchantUser.type);
            string CREATED_AT = nameof(MerchantUser.created_at);
            string UPDATED_AT = nameof(MerchantUser.updated_at);
            string STATE      = nameof(MerchantUser.state);

            if (values.Contains(ID))
            {
                model.id = Convert.ToInt32(values[ID]);
            }

            if (values.Contains(FIRST_NAME))
            {
                model.first_name = Convert.ToString(values[FIRST_NAME]);
            }

            if (values.Contains(LAST_NAME))
            {
                model.last_name = Convert.ToString(values[LAST_NAME]);
            }

            if (values.Contains(EMAIL))
            {
                model.email = Convert.ToString(values[EMAIL]);
            }

            if (values.Contains(CONTANT))
            {
                model.contant = Convert.ToString(values[CONTANT]);
            }

            if (values.Contains(PASSWORD))
            {
                model.password = Convert.ToString(values[PASSWORD]);
            }

            if (values.Contains(TYPE))
            {
                model.type = Convert.ToString(values[TYPE]);
            }

            if (values.Contains(CREATED_AT))
            {
                model.created_at = Convert.ToDateTime(values[CREATED_AT]);
            }

            if (values.Contains(UPDATED_AT))
            {
                model.updated_at = Convert.ToDateTime(values[UPDATED_AT]);
            }

            if (values.Contains(STATE))
            {
                model.state = Convert.ToString(values[STATE]);
            }
        }
Beispiel #15
0
        public static async Task SeedSampleDataAsync(ApplicationDbContext context, string merchantAccountId)
        {
            // Seed, if necessary
            if (!context.Transaction.Any())
            {
                var coldwaterMerchant = new Merchant
                {
                    MerchantName = "Coldwater Creek",
                    MerchantType = MerchantType.StandardMerchant
                };

                var raysMerchant = new Merchant
                {
                    MerchantName = "Rays Carwash",
                    MerchantType = MerchantType.PayFac
                };

                context.Merchant.Add(coldwaterMerchant);
                context.Merchant.Add(raysMerchant);

                await context.SaveChangesAsync();

                var merchantUser = new MerchantUser
                {
                    MerchantId     = coldwaterMerchant.MerchantId,
                    MerchantUserId = merchantAccountId
                };

                context.MerchantUser.Add(merchantUser);

                await context.SaveChangesAsync();

                var transactions = new List <Transaction> {
                    new Transaction {
                        MerchantId = coldwaterMerchant.MerchantId, Amount = 100000, TransactionType = TransactionType.Credit
                    },
                    new Transaction {
                        MerchantId = coldwaterMerchant.MerchantId, Amount = 155665.59, TransactionType = TransactionType.Debit
                    },
                    new Transaction {
                        MerchantId = coldwaterMerchant.MerchantId, Amount = 0.59, TransactionType = TransactionType.Debit
                    },
                    new Transaction {
                        MerchantId = raysMerchant.MerchantId, Amount = 4.99, TransactionType = TransactionType.Debit
                    },
                    new Transaction {
                        MerchantId = raysMerchant.MerchantId, Amount = 10.50, TransactionType = TransactionType.Credit
                    },
                    new Transaction {
                        MerchantId = raysMerchant.MerchantId, Amount = 40.00, TransactionType = TransactionType.Debit
                    },
                    new Transaction {
                        MerchantId = raysMerchant.MerchantId, Amount = 5.00, TransactionType = TransactionType.Debit
                    },
                    new Transaction {
                        MerchantId = raysMerchant.MerchantId, Amount = 4.50, TransactionType = TransactionType.Debit
                    }
                };

                context.Transaction.AddRange(transactions);

                await context.SaveChangesAsync();
            }
        }
Beispiel #16
0
 public MerchantUserCreatedEvent(MerchantUser merchantUser)
 {
     _merchantUser = merchantUser;
 }
        private VisaCheckOut.Models.DTO <VisaCheckOut.Models.VisaCheckoutOutputs.UserOut.MerchantUsersDTO> SaveMerchantUser(CreateMerchantUserInp inp)
        {
            VisaCheckOut.Models.DTO <VisaCheckOut.Models.VisaCheckoutOutputs.UserOut.MerchantUsersDTO> dto = new DTO <MerchantUsersDTO>();
            string useriD = System.Web.HttpContext.Current.User.Identity.GetUserId();

            dto.objname = "CreateMerchantUser";
            string merchantid     = "";
            string merchantname   = "";
            int    merchantuserid = 0;
            string username       = "";

            try
            {
                if (string.IsNullOrEmpty(inp.MerchantID) || string.IsNullOrEmpty(inp.UserID))
                {
                    dto.status = new Models.Status(5);
                    return(dto);
                }
                merchantid = inp.MerchantID;
                username   = inp.UserName;
                var getusername = ve.MerchantUsers.Where(a => a.UserID == inp.UserID).FirstOrDefault();
                if (getusername != null)
                {
                    username = getusername.UserName;
                }
                if (!string.IsNullOrEmpty(inp.MerchantUserID))
                {
                    merchantuserid = Convert.ToInt32(inp.MerchantUserID);


                    var getchkusr = ve.MerchantUsers.Where(a => a.UserID == inp.UserID && a.ID != merchantuserid).FirstOrDefault();

                    if (getchkusr == null)
                    {
                        var getbllrchkusr = ve.MerchantUsers.Where(a => a.UserID == inp.UserID && a.MerchantID == merchantid && a.ID != merchantuserid).FirstOrDefault();
                        if (getbllrchkusr != null)
                        {
                            dto.status = new Models.Status(6);
                            dto.status.statusdescription = "Merchant with same User" + " " + dto.status.statusdescription;
                            return(dto);
                        }
                    }
                    else
                    {
                        var getbllrchkusr = ve.MerchantUsers.Where(a => a.ID != merchantuserid && a.MerchantID == merchantid && a.UserID == inp.UserID).FirstOrDefault();
                        if (getbllrchkusr != null)
                        {
                            dto.status = new Models.Status(6);
                            dto.status.statusdescription = "Merchant with same User" + " " + dto.status.statusdescription;
                            return(dto);
                        }
                        else
                        {
                            var getbllrchkusr1 = ve.MerchantUsers.Where(a => a.ID != merchantuserid && a.UserID == inp.UserID && a.MerchantID != merchantid).FirstOrDefault();
                            if (getbllrchkusr1 != null)
                            {
                                dto.status = new Models.Status(6);
                                dto.status.statusdescription = "User was already assigned to another Merchant";
                                return(dto);
                            }
                            else
                            {
                                dto.status = new Models.Status(6);
                                dto.status.statusdescription = "User was already assigned to another Merchant";
                                return(dto);
                            }
                        }
                    }
                }
                else
                {
                    var getchkusr = ve.MerchantUsers.Where(a => a.UserID == inp.UserID).FirstOrDefault();
                    if (getchkusr == null)
                    {
                        var getbllrchkusr = ve.MerchantUsers.Where(a => a.UserID == inp.UserID && a.MerchantID == merchantid).FirstOrDefault();
                        if (getbllrchkusr != null)
                        {
                            dto.status = new Models.Status(6);
                            dto.status.statusdescription = "Merchant with same User" + " " + dto.status.statusdescription;
                            return(dto);
                        }
                    }
                    else
                    {
                        var getbllrchkusr = ve.MerchantUsers.Where(a => a.MerchantID == merchantid && a.UserID == inp.UserID).FirstOrDefault();
                        if (getbllrchkusr != null)
                        {
                            dto.status = new Models.Status(6);
                            dto.status.statusdescription = "Merchant with same User" + " " + dto.status.statusdescription;
                            return(dto);
                        }
                        else
                        {
                            var getbllrchkusr1 = ve.MerchantUsers.Where(a => a.MerchantID != merchantid && a.UserID == inp.UserID).FirstOrDefault();
                            if (getbllrchkusr1 != null)
                            {
                                dto.status = new Models.Status(6);
                                dto.status.statusdescription = "User was already assigned to another Merchant";
                                return(dto);
                            }
                            else
                            {
                                dto.status = new Models.Status(6);
                                dto.status.statusdescription = "User was already assigned to another Merchant";
                                return(dto);
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(inp.MerchantUserID))
                {
                    merchantid = inp.MerchantID;
                    var getmerchantuser = ve.MerchantUsers.Where(a => a.ID == merchantuserid).FirstOrDefault();
                    if (getmerchantuser != null)
                    {
                        getmerchantuser.MerchantID   = merchantid;
                        getmerchantuser.UserID       = inp.UserID;
                        getmerchantuser.MerchantName = inp.MerchantName;
                        getmerchantuser.UserName     = username;
                        getmerchantuser.UpdatedDate  = DateTime.Now;
                        getmerchantuser.UpdatedBy    = useriD;
                        dto.status                   = new Models.Status();
                        dto.status.statuscode        = "200";
                        dto.status.statusdescription = "OK";
                    }
                }
                else
                {
                    var getmerchanname = ve.Merchants.Where(a => a.MerchantId == merchantid).FirstOrDefault();
                    merchantname = getmerchanname.CompanyPrimaryLegalName;
                    if (getmerchanname != null)
                    {
                        MerchantUser muser = new MerchantUser();
                        muser.MerchantID   = merchantid;
                        muser.MerchantName = merchantname;
                        muser.UserID       = inp.UserID;
                        muser.UserName     = username;
                        muser.Status       = true;
                        muser.CreatedDate  = DateTime.Now;
                        muser.UpdatedDate  = DateTime.Now;
                        ve.MerchantUsers.Add(muser);
                        ve.SaveChanges();
                        dto.status                   = new Models.Status();
                        dto.status.statuscode        = "200";
                        dto.status.statusdescription = "OK";
                    }
                }
            }
            catch (Exception ex)
            {
                Common.TraceLog.WriteToLog(ex.Message.ToString() + "Trace = " + ex.StackTrace.ToString(), ex);
            }
            dto.status = new Models.Status(0);
            return(dto);
        }