Exemplo n.º 1
0
        public void Add(FuelModels model)
        {
            try
            {
                string dateTimeDayNow = DateTime.Now.ToString("ddMMyyyyHHmmss");
                string dateDayNow     = DateTime.Now.ToString("ddMMyyyy");

                db = new BMotionDBEntities();
                Fuel fuelEntity = new Fuel();
                fuelEntity.FuilId          = model.FuelId;
                fuelEntity.Name            = model.FuelName;
                fuelEntity.Price           = model.Price;
                fuelEntity.IsSubsidy       = model.IsSubsidy;
                fuelEntity.BackgroundColor = model.BackgroundColor;
                fuelEntity.TextColor       = model.TextColor;
                fuelEntity.CreatedDate     = DateTime.Now;
                fuelEntity.CreatedBy       = SessionManager.NIP();
                db.Fuels.Add(fuelEntity);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 2
0
        public void AddUserAdmin(UserModels model)
        {
            try
            {
                string dateTimeDayNow = DateTime.Now.ToString("ddMMyyyyHHmmss");
                string dateDayNow     = DateTime.Now.ToString("ddMMyyyy");

                db = new BMotionDBEntities();
                User userEntity = new User();

                userEntity.NIP         = dateTimeDayNow;
                userEntity.Email       = model.Email;
                userEntity.Name        = model.Name;
                userEntity.Password    = model.Password;
                userEntity.CreatedDate = DateTime.Now;
                userEntity.CreatedBy   = SessionManager.NIP();
                userEntity.IsAdmin     = "Y";
                db.Users.Add(userEntity);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 3
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.º 4
0
        public Orders Add(Orders order)
        {
            try
            {
                Guid guidId = Guid.NewGuid();
                db = new BMotionDBEntities();
                Order orderEntity = new Order();
                orderEntity.OrderNo     = guidId.ToString();
                orderEntity.NIP         = order.NIP;
                orderEntity.IsVerify    = "N";
                orderEntity.CreatedDate = DateTime.Now;
                orderEntity.CreatedBy   = orderEntity.NIP;
                orderEntity.ExpiredDate = DateTime.Now.AddHours(4);
                order.ExpiredDate       = DateTime.Now.AddHours(4).ToString("HH:mm");
                db.Orders.Add(orderEntity);
                db.SaveChanges();

                foreach (var item in order.OrderDetails)
                {
                    db = new BMotionDBEntities();

                    var fPrice = from f in db.Fuels
                                 where f.FuilId == item.FuelId
                                 select f.Price;
                    decimal price = Convert.ToDecimal(fPrice.FirstOrDefault().ToString());

                    OrderDetail orderDetailEntity = new OrderDetail();
                    orderDetailEntity.OrderNo     = orderEntity.OrderNo;
                    orderDetailEntity.FuelId      = item.FuelId;
                    orderDetailEntity.Liter       = item.Liter;
                    orderDetailEntity.Price       = price;
                    orderDetailEntity.CreatedDate = DateTime.Now;
                    orderDetailEntity.CreatedBy   = orderEntity.NIP;
                    db.OrderDetails.Add(orderDetailEntity);
                    db.SaveChanges();
                }

                order.OrderNo  = guidId.ToString();
                order.IsVerify = "N";

                return(order);
            }
            catch (Exception e)
            {
                Logging.Log.getInstance().CreateLogError(e, JsonConvert.SerializeObject(order));
                throw e;
            }
        }
Exemplo n.º 5
0
 public void Verification(string documentNo)
 {
     try
     {
         db = new BMotionDBEntities();
         Document doc = (from d in db.Documents
                         where d.DocumentNo.Equals(documentNo)
                         select d).First();
         doc.IsVerify = "Y";
         db.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 6
0
 public void Remove(int FuelId)
 {
     try
     {
         db = new BMotionDBEntities();
         Fuel fuel = (from u in db.Fuels
                      where u.FuilId.Equals(FuelId)
                      select u).First();
         db.Fuels.Remove(fuel);
         db.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 7
0
 public void Verification(UserModels model)
 {
     try
     {
         db = new BMotionDBEntities();
         User usr = (from u in db.Users
                     where u.NIP.Equals(model.NIP)
                     select u).First();
         usr.IsVerify = "Y";
         usr.Password = model.Password;
         db.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 8
0
 public void Update(FuelModels model)
 {
     try
     {
         db = new BMotionDBEntities();
         Fuel fuel = (from u in db.Fuels
                      where u.FuilId.Equals(model.FuelId)
                      select u).First();
         fuel.Name      = model.FuelName;
         fuel.Price     = model.Price;
         fuel.IsSubsidy = model.IsSubsidy;
         db.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 9
0
        public string Add(OrderParameter order)
        {
            try
            {
                Guid guidId = Guid.NewGuid();
                db = new BMotionDBEntities();
                Order orderEntity = new Order();
                orderEntity.OrderNo     = guidId.ToString();
                orderEntity.NIP         = order.NIP;
                orderEntity.IsVerify    = "N";
                orderEntity.CreatedDate = DateTime.Now;
                orderEntity.CreatedBy   = orderEntity.NIP;
                orderEntity.ExpiredDate = DateTime.Now.AddHours(4);
                db.Orders.Add(orderEntity);
                db.SaveChanges();

                foreach (var item in order.Orders)
                {
                    db = new BMotionDBEntities();
                    int  n;
                    bool isNumeric = int.TryParse(item.Liter, out n);
                    if (isNumeric && n != 0)
                    {
                        OrderDetail orderDetailEntity = new OrderDetail();
                        orderDetailEntity.OrderNo     = orderEntity.OrderNo;
                        orderDetailEntity.FuelId      = Convert.ToInt32(item.FuelId);
                        orderDetailEntity.Liter       = n;
                        orderDetailEntity.CreatedDate = DateTime.Now;
                        orderDetailEntity.CreatedBy   = orderEntity.NIP;
                        db.OrderDetails.Add(orderDetailEntity);
                        db.SaveChanges();
                    }
                }
                return(guidId.ToString());
            }
            catch (Exception e)
            {
                Logging.Log.getInstance().CreateLogError(e);
                throw e;
            }
        }
Exemplo n.º 10
0
        public void Add(DocumentModels model)
        {
            try
            {
                //string dateTimeDayNow = DateTime.Now.ToString("ddMMyyyyHHmmss");
                //string dateDayNow = DateTime.Now.ToString("ddMMyyyy");

                if (model.PDF != null)
                {
                    var pathFilePdf = Path.Combine(pathUploads, "Document");
                    var imageName   = Path.GetFileNameWithoutExtension(model.PDF.FileName) + ".webp";

                    db = new BMotionDBEntities();
                    Document docEntity = new Document();
                    docEntity.DocumentNo   = model.DocumentNo;
                    docEntity.NIP          = model.NIP;
                    docEntity.Quota        = model.Quota;
                    docEntity.DocumentFile = imageName;
                    docEntity.ExpDate      = Convert.ToDateTime(model.ExpDate);
                    docEntity.IsVerify     = "Y";
                    docEntity.CreatedDate  = DateTime.Now;
                    docEntity.CreatedBy    = SessionManager.NIP();
                    db.Documents.Add(docEntity);
                    db.SaveChanges();

                    if (!Directory.Exists(pathFilePdf))
                    {
                        System.IO.Directory.CreateDirectory(pathFilePdf);
                    }

                    using (var fileStream = new System.IO.FileStream(pathFilePdf + "\\" + imageName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    {
                        model.PDF.InputStream.CopyTo(fileStream);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 11
0
        public void VerifyOrder(OrderDetails model)
        {
            try
            {
                Nullable <int> literSubsidy = 0;
                db = new BMotionDBEntities();
                OrderDetail dtl = (from d in db.OrderDetails
                                   where d.OrderDetailId.Equals(model.OrderDetailId)
                                   select d).First();
                dtl.IsVerify    = "Y";
                dtl.UpdatedDate = DateTime.Now;
                db.SaveChanges();

                db = new BMotionDBEntities();
                Fuel fl = (from f in db.Fuels
                           where f.FuilId == dtl.FuelId
                           select f).First();
                db = new BMotionDBEntities();
                if (fl.IsSubsidy.ToLower() == "y")
                {
                    literSubsidy = dtl.Liter;
                }
                db = new BMotionDBEntities();
                Order or = (from o in db.Orders
                            where o.OrderNo.Equals(dtl.OrderNo)
                            select o).First();
                db = new BMotionDBEntities();
                Document dc = (from d in db.Documents
                               where d.NIP.Equals(or.NIP) && d.IsVerify.Equals("Y")
                               select d).First();

                dc.Quota = dc.Quota - literSubsidy;
                db.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 12
0
        public Users Add()
        {
            Users user = new Users();

            user.isSuccess = false;
            try
            {
                HttpContext        postedContext = HttpContext.Current;
                HttpFileCollection Request       = postedContext.Request.Files;

                user.NIP        = postedContext.Request.Params["nip"];
                user.Name       = postedContext.Request.Params["name"];
                user.Password   = postedContext.Request.Params["password"];
                user.Phone      = postedContext.Request.Params["phone"];
                user.Profession = postedContext.Request.Params["profession"];
                user.Email      = postedContext.Request.Params["email"];
                user.KTP        = postedContext.Request.Params["ktp"];
                user.District   = postedContext.Request.Params["city"];

                var userList = db.Users.Where(usr => usr.Email.Equals(user.Email) || usr.NIP.Equals(user.NIP)).ToList();
                if (userList.Count == 0)
                {
                    if (Request.Count != 0)
                    {
                        if (Request["imagektp"].ContentType.ToLower() == "image/jpg" ||
                            Request["imagektp"].ContentType.ToLower() == "image/jpeg" ||
                            Request["imagektp"].ContentType.ToLower() == "image/png" ||
                            Request["filepdf"].ContentType.ToLower() == "application/pdf")
                        {
                            HttpPostedFile imgKtp = Request["imagektp"];

                            user.ImageKTP = imgKtp.FileName;
                            var pathImgKtp = Path.Combine(pathUpload, "KTP");//(HttpContext.Current.Server.MapPath(pathUpload), dateDayNow,"KTP");
                            if (!Directory.Exists(pathImgKtp))
                            {
                                System.IO.Directory.CreateDirectory(pathImgKtp);
                            }
                            using (var fileStream = new System.IO.FileStream(pathImgKtp + "\\" + user.ImageKTP, System.IO.FileMode.Create, System.IO.FileAccess.Write))
                            {
                                imgKtp.InputStream.CopyTo(fileStream);
                            }

                            string strUser = user.NIP.ToString().Replace('"', ' ').Replace('\\', ' ').Trim();
                            db = new BMotionDBEntities();
                            User userEntity = new User();
                            userEntity.NIP         = strUser;
                            userEntity.Email       = user.Email.ToString().Replace('"', ' ').Replace('\\', ' ').Trim();
                            userEntity.Name        = user.Name.ToString().Replace('"', ' ').Replace('\\', ' ').Trim();
                            userEntity.Phone       = user.Phone.ToString().Replace('"', ' ').Replace('\\', ' ').Trim();
                            userEntity.KTP         = user.KTP.ToString().Replace('"', ' ').Replace('\\', ' ').Trim();
                            userEntity.Password    = user.Password.ToString().Replace('"', ' ').Replace('\\', ' ');
                            userEntity.CreatedDate = DateTime.Now;
                            userEntity.CreatedBy   = strUser;
                            userEntity.Password    = user.Password.ToString().Replace('"', ' ').Replace('\\', ' ').Trim();
                            userEntity.IsVerify    = "N";
                            userEntity.District    = user.District;
                            //userEntity.verification = user.Verification.ToString().Replace('"', ' ').Replace('"', ' ');
                            //userEntity.Profession = user.Profession.ToString().Replace('"', ' ').Replace('"', ' ');
                            //userEntity.RoleId = user.RoleId;
                            db.Users.Add(userEntity);
                            db.SaveChanges();

                            HttpPostedFile filePdf = Request["filepdf"];
                            if (filePdf != null)
                            {
                                user.ExpDate    = postedContext.Request.Params["expdate"];
                                user.Quota      = postedContext.Request.Params["quota"];
                                user.DocumentNo = postedContext.Request.Params["documentNo"];

                                user.FilePDF = filePdf.FileName;

                                var pathFilePdf = Path.Combine(pathUpload, "Document");//(HttpContext.Current.Server.MapPath(pathUpload),dateDayNow, "Document");

                                if (!Directory.Exists(pathFilePdf))
                                {
                                    System.IO.Directory.CreateDirectory(pathFilePdf);
                                }

                                using (var fileStream = new System.IO.FileStream(pathFilePdf + "\\" + user.FilePDF, System.IO.FileMode.Create, System.IO.FileAccess.Write))
                                {
                                    filePdf.InputStream.CopyTo(fileStream);
                                }

                                db = new BMotionDBEntities();
                                Document docEntity = new Document();
                                docEntity.DocumentNo   = user.DocumentNo;
                                docEntity.NIP          = strUser;
                                docEntity.Quota        = Convert.ToInt32(user.Quota.ToString().Replace('"', ' ').Replace('\\', ' ').Trim());
                                docEntity.DocumentFile = user.FilePDF;
                                docEntity.ExpDate      = Convert.ToDateTime(user.ExpDate.ToString().Replace('"', ' ').Replace('\\', ' ').Trim());
                                docEntity.CreatedDate  = DateTime.Now;
                                docEntity.CreatedBy    = strUser;
                                docEntity.IsVerify     = "N";
                                db.Documents.Add(docEntity);
                                db.SaveChanges();
                            }
                        }
                    }

                    user.isSuccess = true;
                }

                return(user);
            }
            catch (Exception e)
            {
                Logging.Log.getInstance().CreateLogError(e, JsonConvert.SerializeObject(user));
                throw e;
            }
        }
Exemplo n.º 13
0
        public void Add(UserModels model)
        {
            try
            {
                string dateTimeDayNow = DateTime.Now.ToString("ddMMyyyyHHmmss");
                string dateDayNow     = DateTime.Now.ToString("ddMMyyyy");

                db = new BMotionDBEntities();
                User userEntity = new User();
                userEntity.NIP         = model.NIP;
                userEntity.Email       = model.Email;
                userEntity.Name        = model.Name;
                userEntity.Phone       = model.Telp;
                userEntity.KTP         = model.KTP.FileName;
                userEntity.Password    = model.Password;
                userEntity.CreatedDate = DateTime.Now;
                userEntity.CreatedBy   = SessionManager.NIP();
                userEntity.IsVerify    = model.IsVerify;
                userEntity.Profession  = model.Profesi;
                db.Users.Add(userEntity);
                db.SaveChanges();

                var pathImgKtp = Path.Combine(HttpContext.Current.Server.MapPath(pathUpload), dateDayNow, "KTP");

                if (!Directory.Exists(pathImgKtp))
                {
                    System.IO.Directory.CreateDirectory(pathImgKtp);
                }
                using (var fileStream = new System.IO.FileStream(pathImgKtp + "\\" + model.KTP.FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
                {
                    model.KTP.InputStream.CopyTo(fileStream);
                }
                if (model.PDF != null)
                {
                    var pathFilePdf = Path.Combine(HttpContext.Current.Server.MapPath(pathUpload), dateDayNow, "Document");

                    db = new BMotionDBEntities();
                    Document docEntity = new Document();
                    docEntity.DocumentNo   = "Doc_" + dateTimeDayNow;
                    docEntity.NIP          = model.NIP;
                    docEntity.Quota        = model.Quota;
                    docEntity.DocumentFile = model.PDF.FileName;
                    docEntity.ExpDate      = Convert.ToDateTime(model.ExpiredDate);
                    docEntity.CreatedDate  = DateTime.Now;
                    docEntity.CreatedBy    = SessionManager.NIP();
                    db.Documents.Add(docEntity);
                    db.SaveChanges();

                    if (!Directory.Exists(pathFilePdf))
                    {
                        System.IO.Directory.CreateDirectory(pathFilePdf);
                    }
                    using (var fileStream = new System.IO.FileStream(pathFilePdf + "\\" + model.PDF.FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    {
                        model.PDF.InputStream.CopyTo(fileStream);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }