Exemplo n.º 1
0
        public void TestCreditLimit()
        {
            using (var context = new AyerLechonContext())
            {
                var service = new PaymentService(context);

                var summary = new OrderSummaryViewModel()
                {
                    Amount          = 500,
                    DeliveryAddress = "delivery address",
                    Notes           = "notes",
                    PaymentOptionId = PaymentOptionEnum.CreditLine,
                    PhoneNumber     = "Phone Number",
                    OrderDate       = DateTime.Now.ToEpochTime(),
                    RegionId        = null,
                    CustomerId      = 1,
                    OrderDetails    = new List <OrderDetailViewModel>()
                    {
                        new OrderDetailViewModel
                        {
                            Quantity = 1,
                            ItemId   = 1,
                        }
                    }
                };
                service.Create(summary);
            }
        }
Exemplo n.º 2
0
        public void SendResetPasswordMail(string email)
        {
            using (var ctx = new AyerLechonContext())
            {
                var account = ctx.Customers.FirstOrDefault(a => a.Email == email);
                if (account == null)
                {
                    throw new ApplicationException("Email is not registered.");
                }
                ctx.Customers.Attach(account);

                account.ResetPasswordToken = Guid.NewGuid();

                var resetPasswordUrl = ConfigurationManager.AppSettings["BaseUrl"] + "api/password/reset?token=" + account.ResetPasswordToken;

                var body = new StringBuilder();
                body.AppendFormat("<p>Dear {0}, </p>", account.FirstName + " " + account.LastName);
                body.AppendFormat("<p>We received a request to change your password on <a href=\"{0}\">Ayer Lechon</a>. </p>", "http://ayerlechon.com");
                body.Append("<p>Click the link below to set a new password: </p>");
                body.AppendFormat("<h1><a href=\"{0}\">Reset Password</a></h1>", resetPasswordUrl);
                body.AppendFormat("<p>If you do not want to change your password you can ignore this email.</p>", "ResetPassword");
                body.Append("<p>Thanks, </p>");
                body.Append("<p>Ayer Lechon</p>");

                var emailModel = new EmailViewModel()
                {
                    Body    = body.ToString(),
                    EmailTo = email,
                    Subject = "Password Reset"
                };

                _emailService.Send(emailModel);
                ctx.SaveChanges();
            }
        }
Exemplo n.º 3
0
 public HttpResponseMessage SetComplete(int orderSummaryId)
 {
     using (var ctx = new AyerLechonContext())
     {
         try
         {
             var service = new PaymentService(ctx);
             service.SetPaid(orderSummaryId);
             var response = new ResponseViewModel <object>()
             {
                 Status = new Status()
                 {
                     Type    = "Success",
                     Message = "The payment has been compeleted."
                 },
                 Data = null
             };
             return(Request.CreateResponse(HttpStatusCode.OK, response));
         }
         catch (ApplicationException e)
         {
             var response = new ResponseViewModel <object>()
             {
                 Status = new Status()
                 {
                     Type    = "Error",
                     Message = e.Message
                 },
                 Data = null
             };
             return(Request.CreateResponse(HttpStatusCode.BadRequest, response));
         }
     }
 }
Exemplo n.º 4
0
 private bool IsExist(string email)
 {
     using (var ctx = new AyerLechonContext())
     {
         return(ctx.Customers.Any(a => a.Email == email));
     }
 }
Exemplo n.º 5
0
        public HttpResponseMessage Pending()
        {
            using (var ctx = new AyerLechonContext())
            {
                try
                {
                    var service = new PaymentService(ctx);
                    var userId  = UserProvider.GetId();

                    var response = new ResponseViewModel <IEnumerable <OrderSummaryViewModel> >()
                    {
                        Status = new Status()
                        {
                            Type    = "Success",
                            Message = ""
                        },
                        Data = service.GetPendings(userId)
                    };
                    return(Request.CreateResponse(HttpStatusCode.OK, response));
                }
                catch (ApplicationException e)
                {
                    var response = new ResponseViewModel <object>()
                    {
                        Status = new Status()
                        {
                            Type    = "Error",
                            Message = e.Message
                        },
                        Data = null
                    };
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, response));
                }
            }
        }
Exemplo n.º 6
0
        public void DummyItem()
        {
            using (var ctx = new AyerLechonContext())
            {
                //you can change to uploaded file source
                var filepath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\Image\\image.jpg";


                string mimeType = MimeMapping.GetMimeMapping(filepath);


                FileStream stream    = File.OpenRead(filepath);
                byte[]     fileBytes = new byte[stream.Length];

                stream.Read(fileBytes, 0, fileBytes.Length);
                stream.Close();
                //Begins the process of writing the byte array back to a file

                using (Stream file = File.OpenWrite(filepath))
                {
                    file.Write(fileBytes, 0, fileBytes.Length);
                }
                ctx.Items.Add(new Item
                {
                    CategoryID  = 1,
                    Description = "Lechon Belly (49-70 pax)",
                    FileStorage = new FileStorage
                    {
                        MIMEType     = mimeType,
                        FileName     = Path.GetFileName(filepath),
                        UploadedFile = fileBytes
                    },
                    Price      = 2520,
                    ReadyStock = 10,
                });
                ctx.Items.Add(new Item
                {
                    CategoryID  = 1,
                    Description = "Lechon Belly (100-170 pax)",
                    FileStorage = new FileStorage
                    {
                        MIMEType     = mimeType,
                        FileName     = Path.GetFileName(filepath),
                        UploadedFile = fileBytes
                    },
                    Price      = 3520,
                    ReadyStock = 10,
                });
                ctx.SaveChanges();
            }

            //ctx.SaveChanges();
        }
Exemplo n.º 7
0
        public HttpResponseMessage NewVIPApplication()
        {
            using (var ctx = new AyerLechonContext())
            {
                ResponseViewModel <object> response;

                try
                {
                    var userID   = UserProvider.GetId();
                    var customer = ctx.Customers.FirstOrDefault(a => a.CustomerID == userID);
                    if (customer == null)
                    {
                        response = new ResponseViewModel <object>()
                        {
                            Status = new Status()
                            {
                                Type    = "Error",
                                Message = "The customer is not found",
                            },
                            Data = null
                        };
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, response));
                    }
                    ctx.Customers.Attach(customer);
                    customer.NewVIPApplication = true;
                    ctx.SaveChanges();
                    response = new ResponseViewModel <object>()
                    {
                        Status = new Status()
                        {
                            Type    = "Success",
                            Message = "The customer has requested become vip member."
                        },
                        Data = null
                    };
                    return(Request.CreateResponse(HttpStatusCode.OK, response));
                }
                catch (ApplicationException ae)
                {
                    response = new ResponseViewModel <object>()
                    {
                        Status = new Status()
                        {
                            Type    = "Error",
                            Message = ae.Message,
                        },
                        Data = null
                    };
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, response));
                }
            }
        }
Exemplo n.º 8
0
        public HttpResponseMessage Put(ProfileViewModel model)
        {
            ResponseViewModel <object> response = null;

            if (!ModelState.IsValid)
            {
                response = new ResponseViewModel <object>()
                {
                    Status = new Status()
                    {
                        Type          = "Error",
                        Message       = "",
                        FieldMessages = ModelState.ToErrorResponse()
                    },
                    Data = null
                };
                return(Request.CreateResponse(HttpStatusCode.BadRequest, response));
            }

            using (var ctx = new AyerLechonContext())
            {
                try
                {
                    var service = new ProfileService(ctx);
                    service.Update(model);

                    response = new ResponseViewModel <object>()
                    {
                        Status = new Status()
                        {
                            Type    = "Success",
                            Message = "The profile has been updated"
                        },
                        Data = null
                    };
                    return(Request.CreateResponse(HttpStatusCode.OK, response));
                }
                catch (ApplicationException ae)
                {
                    response = new ResponseViewModel <object>()
                    {
                        Status = new Status()
                        {
                            Type    = "Error",
                            Message = ae.Message,
                        },
                        Data = null
                    };
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, response));
                }
            }
        }
Exemplo n.º 9
0
        public void Create(Customer model)
        {
            using (var ctx = new AyerLechonContext())
            {
                if (IsExist(model.Email))
                {
                    throw new ApplicationException("The email is already exist.");
                }

                ctx.Customers.Add(model);
                ctx.SaveChanges();
            }
        }
Exemplo n.º 10
0
        public HttpResponseMessage Get(int id)
        {
            using (var ctx = new AyerLechonContext())
            {
                var imageService = new ImageService(ctx);
                var image        = imageService.Get(id);

                var result = new HttpResponseMessage(HttpStatusCode.OK);
                result.Content = new ByteArrayContent(image.UploadedFile);
                result.Content.Headers.ContentType = new MediaTypeHeaderValue(image.MIMEType);
                return(result);
            }
        }
Exemplo n.º 11
0
 public Customer Login(string username, string password, string deviceId)
 {
     using (var ctx = new AyerLechonContext())
     {
         ILoginDeviceService loginDeviceService = new LoginDeviceService(ctx);
         var account = ctx.Customers.FirstOrDefault(a => a.Email == username && a.Password == password);
         if (account != null)
         {
             loginDeviceService.AddOrUpdate(account.CustomerID, deviceId);
         }
         return(account);
     }
 }
Exemplo n.º 12
0
        public HttpResponseMessage Post(OrderSummaryViewModel model)
        {
            ResponseViewModel <object> response;

            if (!ModelState.IsValid)
            {
                response = new ResponseViewModel <object>()
                {
                    Status = new Status()
                    {
                        Type          = "Error",
                        FieldMessages = ModelState.ToErrorResponse()
                    },
                    Data = null
                };
                return(Request.CreateResponse(HttpStatusCode.BadRequest, response));
            }


            using (var ctx = new AyerLechonContext())
            {
                try
                {
                    var service = new PaymentService(ctx);
                    service.Create(model);
                    response = new ResponseViewModel <object>()
                    {
                        Status = new Status()
                        {
                            Type    = "Success",
                            Message = "The order has been created successfully."
                        },
                        Data = null
                    };
                    return(Request.CreateResponse(HttpStatusCode.OK, response));
                }
                catch (ApplicationException ae)
                {
                    response = new ResponseViewModel <object>()
                    {
                        Status = new Status()
                        {
                            Type    = "Error",
                            Message = ae.Message
                        },
                        Data = null
                    };
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, response));
                }
            }
        }
Exemplo n.º 13
0
 public IEnumerable <RegionViewModel> GetAll()
 {
     using (var ctx = new AyerLechonContext())
     {
         return(ctx.Regions.Where(a => a.ShowOnApp).Select(a => new RegionViewModel()
         {
             Id = a.RegionID,
             Name = a.Name,
             DeliveryFee = a.DeliveryFee,
             IsPickupAtStore = a.IsPickupAtStore,
             IsAirFreight = a.IsAirFreight
         }).OrderBy(a => a.Name).ToList());
     }
 }
Exemplo n.º 14
0
 public void ChangePassword(ChangePasswordViewModel model, int userId)
 {
     using (var ctx = new AyerLechonContext())
     {
         var account = ctx.Customers.FirstOrDefault(a => a.CustomerID == userId && model.CurrentPassword == a.Password);
         if (account == null)
         {
             throw new ApplicationException("The current password is incorrect.");
         }
         ctx.Customers.Attach(account);
         account.Password           = model.NewPassword;
         account.LastChangePassword = DateTimeOffset.Now.ToEpochTime();
         ctx.SaveChanges();
     }
 }
Exemplo n.º 15
0
        public void InitClientTable()
        {
            var ctx = new AyerLechonContext();

            ctx.Clients.Add(new Client()
            {
                Active               = true,
                AllowedOrigin        = "*",
                ApplicationType      = 0,
                Name                 = "IOS",
                RefreshTokenLifeTime = 1,
                Secret               = "919d676f-fead-49eb-990c-b84848448df2",
                ClientID             = Guid.Parse("EE8CF68C-BBA0-4615-A78D-683312CF03E3")
            });
            ctx.SaveChanges();
        }
Exemplo n.º 16
0
        public bool AddRefreshToken(RefreshToken token)
        {
            using (var ctx = new AyerLechonContext())
            {
                var existingToken = ctx.RefreshTokens.FirstOrDefault(r => r.Subject == token.Subject && r.ClientId == token.ClientId);

                if (existingToken != null)
                {
                    ctx.RefreshTokens.Remove(existingToken);
                }

                ctx.RefreshTokens.Add(token);

                return(ctx.SaveChanges() > 0);
            }
        }
Exemplo n.º 17
0
 // GET api/<controller>
 public IHttpActionResult Get()
 {
     using (var ctx = new AyerLechonContext())
     {
         var response = new ResponseViewModel <string>()
         {
             Status = new Status
             {
                 Type    = "Success",
                 Message = ""
             },
             Data = ctx.BankDetails.FirstOrDefault()?.Description ?? string.Empty
         };
         return(Ok(response));
     }
 }
Exemplo n.º 18
0
 public IHttpActionResult Get()
 {
     using (var ctx = new AyerLechonContext())
     {
         var service  = new PaymentOptionService(ctx);
         var response = new ResponseViewModel <IEnumerable <PaymentOptionViewModel> >()
         {
             Status = new Status()
             {
                 Type    = "Success",
                 Message = ""
             },
             Data = service.GetAll(UserProvider.GetId())
         };
         return(Ok(response));
     }
 }
 public IHttpActionResult Get()
 {
     using (var ctx = new AyerLechonContext())
     {
         var orderItemService = new OrderItemService(ctx);
         var response         = new ResponseViewModel <IEnumerable <ProductViewModel> >()
         {
             Status = new Status()
             {
                 Type    = "Success",
                 Message = ""
             },
             Data = orderItemService.GetAll()
         };
         return(Ok(response));
     }
 }
Exemplo n.º 20
0
        public async Task <IHttpActionResult> RegisterExternal(RegisterExternalBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var verifiedAccessToken = await VerifyExternalAccessToken(model.ExternalAccessToken);

            if (verifiedAccessToken == null)
            {
                return(BadRequest("Invalid Provider or External Access Token"));
            }
            using (var context = new AyerLechonContext())
            {
                var customer = context.Customers.Include("LoginDevices").FirstOrDefault(a => a.Email == model.Email);
                if (customer == null)
                {
                    customer = new Customer()
                    {
                        Email     = model.Email,
                        FirstName = model.FirstName,
                        LastName  = model.LastName,
                        VIP       = false
                    };
                }
                var device = context.LoginDevices.FirstOrDefault(a => a.DeviceId == model.DeviceId);
                if (device != null)
                {
                    context.LoginDevices.Remove(device);
                }
                var newdevice = new LoginDevice()
                {
                    DeviceId      = model.DeviceId,
                    CreateDate    = DateTime.Now.ToEpochTime(),
                    FbAccountId   = verifiedAccessToken.user_id,
                    LastLoginDate = DateTime.Now.ToEpochTime(),
                };
                customer.LoginDevices.Add(newdevice);
                context.SaveChanges();

                var accessTokenResponse = GenerateLocalAccessTokenResponse(customer);

                return(Ok(accessTokenResponse));
            }
        }
Exemplo n.º 21
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var allowedOrigin = context.OwinContext.Get <string>("as:clientAllowedOrigin");

            if (allowedOrigin == null)
            {
                allowedOrigin = "*";
            }

            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

            using (var ctx = new AyerLechonContext())
            {
                IAccountService accountService = new AccountService();
                var             deviceId       = context.OwinContext.Get <string>("deviceId");

                var user = accountService.Login(context.UserName, context.Password, deviceId);

                if (user == null)
                {
                    context.SetError("The user name or password is incorrect.");
                    return;
                }

                var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
                identity.AddClaim(new Claim("username", context.UserName));
                identity.AddClaim(new Claim("userid", user.CustomerID.ToString()));

                var props = new AuthenticationProperties(new Dictionary <string, string>
                {
                    {
                        "as:client_id", (context.ClientId == null) ? string.Empty : context.ClientId
                    },
                    {
                        "userName", context.UserName
                    },
                    {
                        "deviceId", deviceId
                    }
                });
                var ticket = new AuthenticationTicket(identity, props);
                context.Validated(ticket);
            }
        }
Exemplo n.º 22
0
        public HttpResponseMessage Redeem(string voucherCode)
        {
            var userId = UserProvider.GetId();

            using (var ctx = new AyerLechonContext())
            {
                var isRedeemed = ctx.OrderSummaries.Include("Discount").Any(a =>
                                                                            a.CustomerID == userId && a.Discount.Code.Trim() == voucherCode.Trim() && (!a.PaymentStatusId.HasValue));
                var path = ConfigurationManager.AppSettings["BaseUrl"] + "api/images/";

                if (isRedeemed)
                {
                    var discount = ctx.Discounts.FirstOrDefault(a => a.Code == voucherCode);
                    var response = new ResponseViewModel <DiscountViewModel>()
                    {
                        Status = new Status()
                        {
                            Type    = "Success",
                            Message = ""
                        },
                        Data = new DiscountViewModel()
                        {
                            Code        = discount.Code,
                            Description = discount.Description,
                            Id          = discount.DiscountID,
                            ImageUrl    = path + discount.Image
                        }
                    };
                    return(Request.CreateResponse(HttpStatusCode.OK, response));
                }
                ;

                var notRedeem = new ResponseViewModel <object>()
                {
                    Status = new Status()
                    {
                        Type    = "Error",
                        Message = "The Voucher Code has been used"
                    },
                    Data = null
                };
                return(Request.CreateResponse(HttpStatusCode.Forbidden, notRedeem));
            }
        }
Exemplo n.º 23
0
        public IHttpActionResult Get()
        {
            var userID = UserProvider.GetId();

            using (var ctx = new AyerLechonContext())
            {
                var service  = new ProfileService(ctx);
                var response = new ResponseViewModel <ProfileViewModel>()
                {
                    Status = new Status()
                    {
                        Type    = "Success",
                        Message = ""
                    },
                    Data = service.Get(userID)
                };
                return(Ok(response));
            }
        }
Exemplo n.º 24
0
        public IHttpActionResult Get()
        {
            var userId = UserProvider.GetId();

            using (var ctx = new AyerLechonContext())
            {
                var discountService = new DiscountService(ctx);
                var response        = new ResponseViewModel <IEnumerable <DiscountViewModel> >()
                {
                    Status = new Status()
                    {
                        Type    = "Success",
                        Message = ""
                    },
                    Data = discountService.GetAll(userId)
                };
                return(Ok(response));
            }
        }
Exemplo n.º 25
0
        public void ResetPassword(string token)
        {
            using (var ctx = new AyerLechonContext())
            {
                var tkn     = Guid.Parse(token);
                var account = ctx.Customers.FirstOrDefault(a => a.ResetPasswordToken == tkn);
                if (account == null)
                {
                    throw new ApplicationException("The token is expired. Please reset your password again.");
                }
                ctx.Customers.Attach(account);

                account.Password           = RandomString(6);
                account.ResetPasswordToken = null;
                account.LastChangePassword = DateTimeOffset.Now.ToEpochTime();

                var body = new StringBuilder();
                body.AppendFormat("<p>Dear {0}, </p>", account.FirstName + " " + account.LastName);
                body.Append("<p>The password has been reset.</p>");
                body.Append("<p>You can now log in with the following credentials:</p>");
                body.AppendFormat("<p>Username: {0}</p>", account.Email);
                body.AppendFormat("<p>New Password: {0}</p>", account.Password);
                body.Append("<br/><br/><p>Thanks, </p>");
                body.Append("<p>Ayer Lechon</p>");

                var emailModel = new EmailViewModel()
                {
                    Body    = body.ToString(),
                    EmailTo = account.Email,
                    Subject = "Your new password"
                };

                _emailService.Send(emailModel);

                ctx.SaveChanges();
            }
        }
Exemplo n.º 26
0
        public void DummyDiscount()
        {
            using (var ctx = new AyerLechonContext())
            {
                var filepath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\Image\\promo.jpeg";


                string mimeType = MimeMapping.GetMimeMapping(filepath);


                FileStream stream    = File.OpenRead(filepath);
                byte[]     fileBytes = new byte[stream.Length];

                stream.Read(fileBytes, 0, fileBytes.Length);
                stream.Close();
                //Begins the process of writing the byte array back to a file

                using (Stream file = File.OpenWrite(filepath))
                {
                    file.Write(fileBytes, 0, fileBytes.Length);
                }

                var expiredDate = DateTime.Now.AddMonths(1).ToEpochTime();
                ctx.Discounts.Add(new Discount
                {
                    Code        = "TESTPROMO3",
                    Description = "Example Promo 3",
                    ExpiredDate = expiredDate,
                    FileStorage = new FileStorage
                    {
                        MIMEType     = mimeType,
                        FileName     = Path.GetFileName(filepath),
                        UploadedFile = fileBytes
                    },
                });
                ctx.Discounts.Add(new Discount
                {
                    Code        = "TESTPROMO4",
                    Description = "Example Promo 4",
                    ExpiredDate = expiredDate,
                    FileStorage = new FileStorage
                    {
                        MIMEType     = mimeType,
                        FileName     = Path.GetFileName(filepath),
                        UploadedFile = fileBytes
                    },
                });
                ctx.Discounts.Add(new Discount
                {
                    Code        = "TESTPROMO5",
                    Description = "Example Promo 5",
                    ExpiredDate = expiredDate,
                    FileStorage = new FileStorage
                    {
                        MIMEType     = mimeType,
                        FileName     = Path.GetFileName(filepath),
                        UploadedFile = fileBytes
                    },
                });
                ctx.SaveChanges();
            }
        }
Exemplo n.º 27
0
 public ProfileService(AyerLechonContext ctx)
 {
     _context = ctx;
 }
Exemplo n.º 28
0
 public PaymentService(AyerLechonContext context)
 {
     _context         = context;
     orderItemService = new OrderItemService(context);
 }
Exemplo n.º 29
0
 public OrderItemService(AyerLechonContext context)
 {
     _context = context;
 }
Exemplo n.º 30
0
 public ImageService(AyerLechonContext context)
 {
     _context = context;
 }