Ejemplo n.º 1
0
        public AddOfferResult Save(AddItemRequest addItemRequest)
        {
            var model  = addItemRequest.ToAddOfferModel(User.UserId);
            var result = BloodSearchModelsRemoteProvider.AddOfferSync(model);

            return(result);
        }
Ejemplo n.º 2
0
        public ActionResult AdminPanel()
        {
            if (!User.IsAdmin)
            {
                return(Redirect("/"));
            }

            var result = BloodSearchModelsRemoteProvider.GetOffers(new GetOffersByFiltersParameters {
                Filter = new SearchFilter {
                    Sort     = SearchFilter.SortEnum.Default,
                    Type     = OfferTypeEnum.Any,
                    Statuses = new List <OfferStateEnum> {
                        OfferStateEnum.New
                    }
                },
                PagingFilter = new PagingFilter {
                    PageNumber = 1,
                    PageSize   = 100
                }
            });

            var model = new AdminPanelResponse {
                Items      = result.Offers,
                TotalCount = result.TotalCount
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        public static BaseResponse Registration(string email, string password, string name = null, string phone = null)
        {
            if (!String.IsNullOrWhiteSpace(email))
            {
                email = email.ToLower().Trim();
            }

            if (!String.IsNullOrEmpty(name))
            {
                name = name.Trim();
            }

            if (!String.IsNullOrEmpty(phone))
            {
                phone = phone.Trim();
            }

            var task = BloodSearchModelsRemoteProvider.Registration(Context, email, GetHash256(password), name, phone);

            if (!task.Success)
            {
                return(new BaseResponse()
                {
                    Success = false,
                    ErrMessages = task.ErrMessages
                });
            }

            Login(email, password);
            return(new BaseResponse());
        }
Ejemplo n.º 4
0
        public PublishOfferResult PublishOffer(long offerId)
        {
            var result = BloodSearchModelsRemoteProvider.GetUserByContext(HttpContext.Current);

            if (!result.Success)
            {
                return(new PublishOfferResult {
                    Success = result.Success,
                    ErrMessages = result.ErrMessages.Select(_ => new KeyValuePair <string, string>(_.Key.ToString(), _.Message)).ToList()
                });
            }

            var publishOfferResult = BloodSearchModelsRemoteProvider.PublishOffer(new PublishOfferModel()
            {
                OfferId = offerId,
                UserId  = result.Id,
                IsAdmin = User.IsAdmin
            });

            if (!publishOfferResult.Success)
            {
                return(new PublishOfferResult {
                    Success = publishOfferResult.Success,
                    ErrMessages = publishOfferResult.ErrMessages
                });
            }

            return(publishOfferResult);
        }
Ejemplo n.º 5
0
        public DeleteOfferResult DeleteOffer(long offerId)
        {
            var result = BloodSearchModelsRemoteProvider.GetUserByContext(HttpContext.Current);

            if (!result.Success)
            {
                return(new DeleteOfferResult {
                    Success = result.Success,
                    ErrMessages = result.ErrMessages.Select(x => new KeyValuePair <string, string>(x.Key.ToString(), x.Message)).ToList()
                });
            }

            var deleteOfferResult = BloodSearchModelsRemoteProvider.DeleteOffer(new DeleteOfferModel {
                OfferId = offerId,
                UserId  = result.Id,
                IsAdmin = User.IsAdmin
            });

            if (!deleteOfferResult.Success)
            {
                return(new DeleteOfferResult {
                    Success = deleteOfferResult.Success,
                    ErrMessages = deleteOfferResult.ErrMessages
                });
            }

            return(deleteOfferResult);
        }
Ejemplo n.º 6
0
        public ActionResult Index(long?id)
        {
            var model = new AddItemRequest();

            if (id.HasValue)
            {
                try {
                    var getOfferResult = BloodSearchModelsRemoteProvider.GetOffer(id.Value);
                    if (getOfferResult.UserId != User.UserId)
                    {
                        return(Redirect("/"));
                    }
                    model = AddItemRequest.FromOfferResult(getOfferResult);
                } catch {
                    return(Redirect("/"));
                }
            }
            else
            {
                model.Name  = User.Name;
                model.Phone = User.Phone;
                model.Email = User.Email;
            }

            return(View(model));
        }
Ejemplo n.º 7
0
        public new ActionResult Profile()
        {
            var model = new ProfileResponse {
                Email = User.Email,
                Name  = User.Name,
                Phone = User.Phone,
                Items = BloodSearchModelsRemoteProvider.GetOffersByUser(User.UserId)
            };

            return(View(model));
        }
Ejemplo n.º 8
0
        public ActionResult Index(long id)
        {
            var model = new GetOfferResult();

            try {
                model = BloodSearchModelsRemoteProvider.GetOffer(id);
            }
            catch {
                return(Redirect("/"));
            }
            return(View(model));
        }
Ejemplo n.º 9
0
        public static LoginResult Login(string email, string password)
        {
            if (!String.IsNullOrWhiteSpace(email))
            {
                email = email.ToLower().Trim();
            }

            var task = BloodSearchModelsRemoteProvider.Login(Context, email, GetHash256(password));

            if (!task.IsAuth || !task.Success)
            {
                return(new LoginResult()
                {
                    Success = false,
                    ErrMessages = task.ErrMessages
                });
            }

            return(task);
        }
Ejemplo n.º 10
0
        public BaseResponse UpdateProfileInfo(ProfileViewModel request)
        {
            var user = BloodSearchModelsRemoteProvider.GetUserByContext(HttpContext.Current);

            if (!user.Success)
            {
                return(new BaseResponse()
                {
                    Success = false,
                    ErrMessages = user.ErrMessages
                });
            }

            var result = BloodSearchModelsRemoteProvider.EditUser(new EditUserRequest()
            {
                Token  = Token,
                Name   = request.Name,
                UserId = UserId,
                Phone  = request.Phone
            });

            return(result);
        }
Ejemplo n.º 11
0
        public ActionResult Index(QueryParameters parameters)
        {
            var model = new SearchItemsIndexResponse(System.Web.HttpContext.Current)
            {
                QueryParameters = parameters
            };

            var filters = OffersQueryParamsUtils.ParseFilterFromQueryParameters(parameters);

            model.Filter = filters.Filter;

            model.PagingFilter = filters.PagingFilter;

            var result = BloodSearchModelsRemoteProvider.GetOffers(new GetOffersByFiltersParameters {
                Filter       = filters.Filter,
                PagingFilter = filters.PagingFilter
            });

            model.Items = result.Offers;

            model.TotalCount = result.TotalCount;

            return(View(model));
        }