示例#1
0
        public IHttpActionResult PostOffer(Offer offer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            else
            {
                var stream   = new MemoryStream(offer.ImageArray);
                var guid     = Guid.NewGuid().ToString();
                var file     = string.Format("{0}.jpg", guid);
                var folder   = "~\\Content\\OfferData";
                var fullpath = string.Format("{0}\\{1}", folder, file);
                var response = Filehelpers.UploadPhoto(stream, folder, file);

                var Data = new Offer
                {
                    Description = offer.Description,
                    ImagePath   = fullpath,
                    ExpiryDate  = offer.ExpiryDate,
                    IsAvailable = offer.IsAvailable,
                    Title       = offer.Title
                };
                db.Offers.Add(Data);
                db.SaveChanges();
                return(Ok(Data));
            }
        }
        public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            else
            {
                var stream   = new MemoryStream(model.ImageArray);
                var guid     = Guid.NewGuid().ToString();
                var file     = string.Format("{0}.jpg", guid);
                var folder   = "~\\Content\\UserData";
                var fullpath = string.Format("{0}\\{1}", folder, file);
                var response = Filehelpers.UploadPhoto(stream, folder, file);


                var user = new ApplicationUser()
                {
                    UserName    = model.Alias,
                    Email       = model.Email,
                    Alias       = model.Alias,
                    PhoneNumber = model.PhoneNumber,
                    DateJoined  = model.DateJoined,
                    ImagePath   = fullpath
                };

                IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                if (!result.Succeeded)
                {
                    return(GetErrorResult(result));
                }

                return(Ok());
            }
        }