Пример #1
0
 public List <MerchantModel> GetBy(MerchantBindingModel md)
 {
     try
     {
         var merchants = _merchantLogic.GetBy(int.Parse(md.action), int.Parse(md.value));
         var entities  = Mapper.Map <List <MerchantModel> >(merchants);
         return(entities);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
        public async Task <IHttpActionResult> Register(MerchantBindingModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }



                using (DunkeyContext ctx = new DunkeyContext())
                {
                    if (ctx.Admins.Any(x => x.Email == model.Email))
                    {
                        return(Content(HttpStatusCode.OK, new CustomResponse <Error>
                        {
                            Message = "Conflict",
                            StatusCode = (int)HttpStatusCode.Conflict,
                            Result = new Error {
                                ErrorMessage = "Merchant with email already exists"
                            }
                        }));
                        //return BadRequest("User with the same email already exists.");

                        //return Request.CreateResponse(HttpStatusCode.OK, new Error { ErrorCode = "400 Conflict", Message = "User with email already exist"});
                    }
                    else
                    {
                        Admin adminModel = new Admin
                        {
                            FirstName = model.FirstName,
                            LastName  = model.LastName,
                            Email     = model.Email,
                            //Password = "******", //model.Password,
                            FullName     = model.FirstName + " " + model.LastName,
                            BusinessName = model.BusinessName,
                            BusinessType = model.BusinessType,
                            Status       = (int)Global.StatusCode.NotVerified,
                            Phone        = model.Phone,
                            Role         = model.Role
                        };

                        ctx.Admins.Add(adminModel);
                        ctx.SaveChanges();
                        using (AdminViewModel adminViewModel = new AdminViewModel(adminModel))
                        {
                            //userViewModel.Token = await Utility.GenerateToken(userModel.Email, userModel.Password, Request);
                            CustomResponse <AdminViewModel> response = new CustomResponse <AdminViewModel> {
                                Message = "Success", StatusCode = (int)HttpStatusCode.OK, Result = adminViewModel
                            };
                            return(Ok(response));
                            //return Request.CreateResponse(HttpStatusCode.OK, response);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(DunkeyDelivery.Utility.LogError(ex)));
            }
        }