Exemplo n.º 1
0
        public ResponseUsers Register()
        {
            Users user = UserLogic.getInstance().Add();

            try
            {
                db = new BMotionDBEntities();
                var quota        = db.sp_UserQuota(user.NIP).FirstOrDefault();
                var purchasedBBM = db.sp_UserPurchasedBBM(user.NIP).FirstOrDefault();
                if (user.isSuccess)
                {
                    return(new ResponseUsers
                    {
                        status = "success",
                        message = "user successfully inserted",
                        Data = new Users
                        {
                            Email = user.Email,
                            Name = user.Name,
                            NIP = user.NIP,
                            Phone = user.Phone,
                            Profession = user.Profession,
                            Quota = quota.Quota == null ? "0 Ltr" : quota.Quota,
                            PurchaseBBM = purchasedBBM == null ? "0 Ltr" : purchasedBBM,
                            Password = user.Password,
                            Verification = "N",
                            ImageProfilePath = string.Format("{0}/{1}", pathImageProfile, user.KTP)
                        }
                    });
                }
                else
                {
                    return(new ResponseUsers
                    {
                        status = "failed",
                        message = "user already",
                    });
                }
            }
            catch (Exception e)
            {
                Logging.Log.getInstance().CreateLogError(e, JsonConvert.SerializeObject(user));
                return(new ResponseUsers
                {
                    status = "failed",
                    message = e.Message
                });
            }
        }
Exemplo n.º 2
0
        public ActionResult OrderFuel(string NIP)
        {
            try
            {
                NewOrder order = new Models.NewOrder();
                if (db.Users.Where(u => u.NIP.Equals(NIP)).Count() != 0)
                {
                    var user = UserLogic.getInstance().GetUserById(NIP);
                    if (user.IsVerify.ToLower() == "y")
                    {
                        var quota = db.sp_UserQuota(NIP).FirstOrDefault();
                        order.NIP   = user.NIP;
                        order.Nama  = user.Name;
                        order.Phone = user.Telp;
                        order.Email = user.Email;
                        order.Quota = quota.Quota;

                        FuelOrder            fuel       = new FuelOrder();
                        List <FuelItemOrder> subsidi    = new List <FuelItemOrder>();
                        List <FuelItemOrder> nonSubsidi = new List <FuelItemOrder>();

                        List <Fuel> fuelList = FuelLogic.getInstance().getAllFuel();
                        for (int i = 0; i < fuelList.Count; i++)
                        {
                            FuelItemOrder item = new FuelItemOrder();

                            item.FuelId = fuelList[i].FuilId.ToString();
                            item.Fuel   = fuelList[i].Name;

                            if (fuelList[i].IsSubsidy.ToLower() == "y")
                            {
                                subsidi.Add(item);
                            }
                            else
                            {
                                nonSubsidi.Add(item);
                            }
                        }

                        fuel.Subsidi    = subsidi;
                        fuel.NonSubsidi = nonSubsidi;

                        order.Fuel = fuel;

                        return(Json(order, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json("Failed", JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    return(Json("Failed", JsonRequestBehavior.AllowGet));
                }
                //OrderDetails detail = new OrderDetails();
                //Orders orderDetails = new Orders();

                //List<OrderDetails> listDetail = new List<OrderDetails>();

                //if (arrValue != null)
                //{
                //    string[] arrNIP = arrValue[0].Split(',');
                //    string[] arrFuelId = arrValue[1].Split(',');
                //    string[] arrLiter = arrValue[2].Split(',');

                //    if (order.NIP == null)
                //    {
                //        order = new Models.Orders();
                //        order.NIP = arrNIP[0];
                //    }

                //    for (int i = 0; i < arrFuelId.Length; i++)
                //    {
                //        detail = new OrderDetails();
                //        detail.FuelId = Convert.ToInt32(arrFuelId[i]);
                //        detail.Liter = Convert.ToInt32(arrLiter[i]);
                //        listDetail.Add(detail);
                //    }

                //    order.OrderDetails = listDetail;
                //    orderDetails = OrdersLogic.getInstance().Add(order);
                //}

                //return Json(orderDetails, JsonRequestBehavior.AllowGet);
            }
            catch (Exception e)
            {
                Logging.Log.getInstance().CreateLogError(e);
                return(Json(e.Message, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 3
0
 public ResponseUsers Login(Users user)
 {
     try
     {
         var userList = db.Users.Where(usr => usr.Email.Equals(user.Email) && usr.Password.Equals(user.Password)).ToList();
         if (userList.Count > 0)
         {
             var quota        = db.sp_UserQuota(userList.FirstOrDefault().NIP).FirstOrDefault();
             var purchasedBBM = db.sp_UserPurchasedBBM(userList.FirstOrDefault().NIP).FirstOrDefault();
             return(new ResponseUsers
             {
                 status = "success",
                 message = "user found",
                 Data = new Users
                 {
                     Email = userList.FirstOrDefault().Email,
                     Name = userList.FirstOrDefault().Name,
                     NIP = userList.FirstOrDefault().NIP,
                     Phone = userList.FirstOrDefault().Phone,
                     Profession = userList.FirstOrDefault().Profession,
                     Quota = quota.Quota,
                     PurchaseBBM = purchasedBBM,
                     Password = userList.FirstOrDefault().Password,
                     Verification = userList.FirstOrDefault().IsVerify,
                     ImageProfilePath = string.Format("{0}/{1}", pathImageProfile, userList.FirstOrDefault().KTP)
                 }
             });
         }
         else
         {
             userList = db.Users.Where(usr => usr.Phone.Equals(user.Email) && usr.Password.Equals(user.Password)).ToList();
             if (userList.Count > 0)
             {
                 var quota        = db.sp_UserQuota(userList.FirstOrDefault().NIP).FirstOrDefault();
                 var purchasedBBM = db.sp_UserPurchasedBBM(userList.FirstOrDefault().NIP).FirstOrDefault();
                 return(new ResponseUsers
                 {
                     status = "success",
                     message = "user success login",
                     Data = new Users
                     {
                         Email = userList.FirstOrDefault().Email,
                         Name = userList.FirstOrDefault().Name,
                         NIP = userList.FirstOrDefault().NIP,
                         Phone = userList.FirstOrDefault().Phone,
                         Profession = userList.FirstOrDefault().Profession,
                         Quota = quota.Quota,
                         PurchaseBBM = purchasedBBM,
                         Password = userList.FirstOrDefault().Password,
                         Verification = userList.FirstOrDefault().IsVerify,
                         ImageProfilePath = string.Format("{0}/{1}", pathImageProfile, userList.FirstOrDefault().KTP)
                     }
                 });
             }
             else
             {
                 return(new ResponseUsers
                 {
                     status = "failed",
                     message = "user failed login"
                 });
             }
         }
     }
     catch (Exception e)
     {
         Logging.Log.getInstance().CreateLogError(e, JsonConvert.SerializeObject(user));
         return(new ResponseUsers
         {
             status = "failed",
             message = e.Message
         });
     }
 }