예제 #1
0
        public static int CreateLandlord(Landlord entity)
        {
            try
            {

                using (var ctx = new PosContext())
                {
                    var found = ctx.Landlord.FirstOrDefault(a => a.Email == entity.Email);
                    if (found == null)
                    {
                        var model = ctx.Landlord.Add(entity);
                        ctx.SaveChanges();
                        AgencyContext.AddNewLandlord(model);
                        return model.Id;
                    }
                    else
                    {
                        //TODO If landlord is found he might have an account, maybe with another agency
                        /*TODO HE May also be created without being invited to the site so he has no login so need to check
                         * TODO whether or not the agency want to link him to one of the entities within their database
                         *
                        */

                    }
                    return -1;

                }

            }
            catch (Exception ex)
            {
                return -1;
            }
        }
예제 #2
0
        public static int CreateLog(Log log)
        {
            try
            {

                using (var ctx = new PosContext())
                {
                    var email = HttpContext.Current.User.Identity.Name;
                    log.CreatedByEmail = email;
                    var found = ctx.Log.FirstOrDefault(a => a.Id == log.Id);

                    if (found == null)
                    {

                        log.CreatedDateTime = DateTime.Now;
                        var model = ctx.Log.Add(log);
                        ctx.SaveChanges();
                        return model.Id;
                    }
                    return -1;

                }

            }
            catch (Exception ex)
            {
                return -1;
            }
        }
예제 #3
0
        public void WhenAddingAUTable_TablesTableCountIsIncrementedByOne()
        {
            int beforeCount = 0;
            int afterCount  = 0;

            using (var db = new PosContext())
            {
                beforeCount = db.Allergens.Count();

                allergenCRUD.Create("testName");

                afterCount = db.Allergens.Count();
            }
            Assert.AreEqual(beforeCount + 1, afterCount);
        }
예제 #4
0
        public static List<Property> GetAgencyProperties(int? agencyId)
        {
            try
            {
                using (var ctx = new PosContext())
                {
                    var model = ctx.Property.Where(l => l.AgencyId == agencyId).Include(l => l.Agency).Include(l => l.Landlord).Include(l => l.Rooms).ToList();
                    return (model);
                }

            }
            catch (Exception ex)
            {
                return null;
            }
        }
예제 #5
0
        public static List<LogArchive> GetLogArchive(int? id)
        {
            try
            {
                using (var ctx = new PosContext())
                {
                    var model = ctx.LogArchive.Where(l => l.Log.Id == id).ToList();
                    return (model);
                }

            }
            catch (Exception ex)
            {
                return null;
            }
        }
예제 #6
0
        public static Log GetLog(int logId)
        {
            try
            {
                using (var ctx = new PosContext())
                {
                    var model = ctx.Log.Include(l => l.Property).Include(l => l.AssignedContractor).FirstOrDefault(l => l.Id == logId);
                    return (model);
                }

            }
            catch (Exception ex)
            {
                return null;
            }
        }
예제 #7
0
        public void WhenDeletingATable_TablesTableCountIsDecrementedByOne()
        {
            int beforeCount = 0;
            int afterCount  = 0;

            using (var db = new PosContext())
            {
                db.Allergens.Add(TestAllergen);
                db.SaveChanges();
                allergenCRUD.selectedAllergen = TestAllergen;
                beforeCount = db.Allergens.Count();
                allergenCRUD.Remove(TestAllergen.AllergenID);
                afterCount = db.Allergens.Count();
            }
            Assert.AreEqual(beforeCount - 1, afterCount);
        }
예제 #8
0
        public void WhenDeletingATable_TablesTableCountIsDecrementedByOne()
        {
            int beforeCount = 0;
            int afterCount  = 0;

            using (var db = new PosContext())
            {
                db.Tables.Add(TestTable);
                db.SaveChanges();
                tableCRUD.selectedTable = TestTable;
                beforeCount             = db.Tables.Count();
                tableCRUD.Delete(TestTable.TableName);
                afterCount = db.Tables.Count();
            }
            Assert.AreEqual(beforeCount - 1, afterCount);
        }
예제 #9
0
        public void Remove(int orderID)
        {
            using (var db = new PosContext())
            {
                db.Orders.Remove(db.Orders.Find(orderID));
                db.SaveChanges();
            }

            for (int i = 0; i < currentOrders.Count; i++)
            {
                if (currentOrders[i].OrderID == orderID)
                {
                    currentOrders.RemoveAt(i);
                }
            }
        }
예제 #10
0
        public static int GetAgentsAgency(string agentsEmail)
        {
            try
            {
                using (var ctx = new PosContext())
                {
                    var model = ctx.Agency.FirstOrDefault(l => l.AgencyEmail == agentsEmail);
                    return model.Id;
                }

            }
            catch (Exception ex)
            {
                return -1;
            }
        }
예제 #11
0
        public void WhenDeletingATable_TablesTableCountIsDecrementedByOne()
        {
            int beforeCount = 0;
            int afterCount  = 0;

            using (var db = new PosContext())
            {
                db.Products.Add(TestProduct);
                db.SaveChanges();
                productCrud.selectedProduct = TestProduct;
                beforeCount = db.Products.Count();
                productCrud.Remove(TestProduct.ProductName);
                afterCount = db.Products.Count();
            }
            Assert.AreEqual(beforeCount - 1, afterCount);
        }
예제 #12
0
        public void WhenDeletingATable_TablesTableCountIsDecrementedByOne()
        {
            int beforeCount = 0;
            int afterCount  = 0;

            using (var db = new PosContext())
            {
                db.ProductCategories.Add(TestProductCategory);
                db.SaveChanges();
                productCategoryCRUD.selectedProductCategory = TestProductCategory;
                beforeCount = db.ProductCategories.Count();
                productCategoryCRUD.Delete(TestProductCategory.ProductCategoryName);
                afterCount = db.ProductCategories.Count();
            }
            Assert.AreEqual(beforeCount - 1, afterCount);
        }
예제 #13
0
파일: TableCRUD.cs 프로젝트: tzinakos/POS
        public void Create(string tableName, string tableSite, int userID = 1, int tableStatusID = 1, int tableSeets = 4)
        {
            using (var db = new PosContext())
            {
                db.Tables.Add(new Table
                {
                    TableName     = tableName,
                    TableSeats    = tableSeets,
                    TableStatusID = 1,
                    UserID        = userID,
                    TableSite     = tableSite
                });

                db.SaveChanges();
            }
        }
예제 #14
0
        public static Landlord GetLandlordByEmail(string email)
        {
            try
            {
                using (var ctx = new PosContext())
                {
                    var model = ctx.Landlord.FirstOrDefault(l => l.Email == email);
                    return model;
                }

            }
            catch (Exception ex)
            {
                return null;
            }
        }
예제 #15
0
 public void Create(string productName, double productPrice, string productDescription, int productQuantity, int categoryID, int allergentID)
 {
     using (var db = new PosContext())
     {
         db.Products.Add(new Product
         {
             ProductCategoryID  = categoryID,
             ProductDescription = productDescription,
             ProductName        = productName,
             ProductPrice       = productPrice,
             ProductQuantity    = productQuantity,
             AllergenID         = allergentID
         });
         db.SaveChanges();
     }
 }
예제 #16
0
        public static Landlord GetLandlordById(int id)
        {
            try
            {
                using (var ctx = new PosContext())
                {
                    var model = ctx.Landlord.FirstOrDefault(l => l.Id == id);
                    return model;
                }

            }
            catch (Exception ex)
            {
                return null;
            }
        }
예제 #17
0
        public static Agency GetAgency(string currentEmail)
        {
            try
            {
                using (var ctx = new PosContext())
                {
                    var model = ctx.Agency.FirstOrDefault(l => l.AgencyEmail == currentEmail);
                    return (model);
                }

            }
            catch (Exception ex)
            {
                return null;
            }
        }
예제 #18
0
        public void WhenDeletingAUser_UsersTableCountIsDecrementedByOne()
        {
            int beforeCount = 0;
            int afterCount  = 0;

            using (var db = new PosContext())
            {
                db.Users.Add(TestUser);
                db.SaveChanges();
                userCRUD.selectedUser = TestUser;
                beforeCount           = db.Users.Count();
                userCRUD.Delete(TestUser.UserID);
                afterCount = db.Users.Count();
            }
            Assert.AreEqual(beforeCount - 1, afterCount);
        }
예제 #19
0
        public static Contractor GetContractorByEmail(string email)
        {
            try
            {
                using (var ctx = new PosContext())
                {
                    var model = ctx.Contractor.FirstOrDefault(l => l.Email == email);
                    return model;
                }

            }
            catch (Exception ex)
            {
                return null;
            }
        }
예제 #20
0
        //Create dan Edit
        public static bool Update(SupplierViewModel model)
        {
            bool result = true;

            try
            {
                using (var db = new PosContext())
                {
                    if (model.Id == 0)
                    {
                        Supplier supplier = new Supplier();
                        supplier.Id          = model.Id;
                        supplier.Nama        = model.Nama;
                        supplier.Alamat      = model.Alamat;
                        supplier.NoTelp      = model.NoTelp;
                        supplier.IsActivated = model.IsActivated;
                        supplier.CreatedBy   = "Arief";
                        supplier.CreatedDate = DateTime.Now;

                        db.Mst_Suppliers.Add(supplier);
                        db.SaveChanges();
                    }
                    else
                    {
                        Supplier supplier = db.Mst_Suppliers.Where(d => d.Id == model.Id).FirstOrDefault();
                        if (supplier != null)
                        {
                            supplier.Nama         = model.Nama;
                            supplier.Alamat       = model.Alamat;
                            supplier.NoTelp       = model.NoTelp;
                            supplier.IsActivated  = model.IsActivated;
                            supplier.ModifiedBy   = "Arief";
                            supplier.ModifiedDate = DateTime.Now;

                            db.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result  = false;
                Message = ex.Message;
            }

            return(result);
        }
예제 #21
0
        public static List<File> GetPropertyImages(int? id)
        {
            try
            {
                using (var ctx = new PosContext())
                {
                    var model = ctx.File.Where(f => f.PropertyId == id).ToList();
                    return model;
                }

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return null;
            }
        }
예제 #22
0
        public static List <TokoViewModel> GetAll()
        {
            List <TokoViewModel> result = new List <TokoViewModel>();

            using (var db = new PosContext())
            {
                result = (from tk in db.Mst_Tokos
                          select new TokoViewModel
                {
                    Id = tk.Id,
                    Nama = tk.Nama,
                    Alamat = tk.Alamat,
                    NoTelp = tk.NoTelp
                }).ToList();
            }
            return(result);
        }
예제 #23
0
        public ActionResult Delete(int id)
        {
            var CustomerId = new SqlParameter("CustomerId", SqlDbType.Int);

            CustomerId.Value = id;
            using (PosContext db = new PosContext())
            {
                /* By using Entity Framework
                *  Customer cust = db.Customers.Where(x => x.CustomerId == id).FirstOrDefault<Customer>();
                *  db.Customers.Remove(cust);*/

                //By Using stored Procedure
                db.Database.ExecuteSqlCommand("exec Customer_Delete  @CustomerId", CustomerId);
                db.SaveChanges();
                return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #24
0
        public static File GetFile(int? id)
        {
            try
            {
                using (var ctx = new PosContext())
                {
                    var model = ctx.File.FirstOrDefault(t => t.Id == id);
                    return model;
                }

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return null;
            }
        }
예제 #25
0
 public void Setup()
 {
     using (var db = new PosContext())
     {
         productCategoryID = db.ProductCategories.Where(pc => pc.ProductCategoryName == "Test").Select(pc => pc.ProductCategoryID).FirstOrDefault();
         allergentID       = db.Allergens.Where(a => a.AllergenName == "Test").Select(a => a.AllergenID).FirstOrDefault();
     }
     TestProduct = new Product
     {
         AllergenID         = allergentID,
         ProductCategoryID  = productCategoryID,
         ProductDescription = "TestDescription",
         ProductName        = "TestName",
         ProductPrice       = 2.5,
         ProductQuantity    = 3
     };
 }
예제 #26
0
        public static int CreateFile(File model)
        {
            try
            {
                using (var ctx = new PosContext())
                {
                    ctx.File.Add(model);
                    ctx.SaveChanges();
                    return model.Id;
                }

            }
            catch (Exception ex)
            {
                return -1;
            }
        }
예제 #27
0
        public ActionResult AddorEdit(Customer cust)//we have to pass instance of object in defined stages of enity that's we have created instance
        {
            var CustomerId = new SqlParameter("CustomerId", SqlDbType.Int);

            CustomerId.Value = cust.CustomerId;
            var CustomerName = new SqlParameter("CustomerName", SqlDbType.NVarChar);

            CustomerName.Value = cust.CustomerName;
            var CustomerAddress = new SqlParameter("CustomerAddress", SqlDbType.NVarChar);

            CustomerAddress.Value = cust.CustomerAddress;
            var CustomerGender = new SqlParameter("Gender", SqlDbType.NVarChar);

            CustomerGender.Value = cust.Gender;
            using (PosContext db = new PosContext())
            {
                if (cust.CustomerId == 0 && ModelState.IsValid)
                {
                    /*By using Entity Framework
                     * db.Customers.Add(cust);*/
                    //By using Stored Procedure
                    db.Database.ExecuteSqlCommand("exec Customer_Insert @CustomerName,@CustomerAddress,@Gender", CustomerName, CustomerAddress, CustomerGender);
                    db.SaveChanges();
                    return(Json(new { success = true, message = "saved Successfully" }, JsonRequestBehavior.AllowGet));
                }
                else if (cust.CustomerId != 0 && ModelState.IsValid)
                {
                    /*By using Entity framework
                     * db.Entry(cust).State = EntityState.Modified;*/
                    //By using Stored Procedure
                    db.Database.ExecuteSqlCommand("exec Customer_Update  @CustomerId,@CustomerName,@CustomerAddress,@Gender", CustomerId, CustomerName, CustomerAddress, CustomerGender);
                    db.SaveChanges();
                    return(Json(new { success = true, message = "saved Successfully" }, JsonRequestBehavior.AllowGet));
                }
                else if (!ModelState.IsValid)
                {
                    ModelState.AddModelError("CustomerName", "Name is Required");
                    return(View());
                }
                else
                {
                    return(View(cust));
                }
            }
        }
예제 #28
0
        public static ReturnValueViewModel SaveSelling(HeaderDetailPenjualanViewModel model)
        {
            ReturnValueViewModel result = new ReturnValueViewModel();

            result.Success   = true;
            result.Referensi = GetNewReference();

            try
            {
                using (var db = new PosContext())
                {
                    HeaderPenjualan sh = new HeaderPenjualan();
                    sh.Id               = 1;
                    sh.IdPembeli        = model.IdPembeli;
                    sh.Referensi        = result.Referensi;
                    sh.TanggalPenjualan = DateTime.Now;
                    sh.CreatedDate      = DateTime.Now;
                    sh.CreatedBy        = "Arief";

                    db.Trans_HeaderPenjualans.Add(sh);

                    foreach (var item in model.Details)
                    {
                        DetailPenjualan sd = new DetailPenjualan();
                        sd.IdHeaderPenjualan = sh.Id;
                        sd.IdBarang          = item.IdBarang;
                        sd.HargaPenjualan    = item.HargaPenjualan;
                        sd.JumlahBarang      = item.JumlahBarang;
                        sd.Total             = item.HargaPenjualan * item.JumlahBarang; //item.Amount;
                        sd.CreatedBy         = "Arief";
                        sd.CreatedDate       = DateTime.Now;

                        db.Trans_DetailPenjualans.Add(sd);
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.InnerException.ToString();
            }
            return(result);
        }
예제 #29
0
        public static List <SupplierViewModel> GetAll()
        {
            List <SupplierViewModel> result = new List <SupplierViewModel>();

            using (var db = new PosContext())
            {
                result = (from sup in db.Mst_Suppliers
                          select new SupplierViewModel
                {
                    Id = sup.Id,
                    Nama = sup.Nama,
                    Alamat = sup.Alamat,
                    NoTelp = sup.NoTelp,
                    IsActivated = sup.IsActivated
                }).ToList();
            }
            return(result);
        }
예제 #30
0
        public static List<Log> GetPropertyLogs(int? propertyId)
        {
            try
            {
                using (var ctx = new PosContext())
                {
                    var model = ctx.Log.Where(l => l.PropertyId == propertyId).
                        Include(l => l.Property).
                        Include(l => l.AssignedContractor).ToList();
                    return (model);
                }

            }
            catch (Exception ex)
            {
                return null;
            }
        }
예제 #31
0
 public ActionResult AddorEdit_Product(Product prod)//we have to pass instance of object in defined stages of enity that's we have created instance
 {
     using (PosContext db = new PosContext())
     {
         if (prod.ProductId == 0)
         {
             db.Products.Add(prod);
             db.SaveChanges();
             return(Json(new { success = true, message = "saved Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             db.Entry(prod).State = EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "saved Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
예제 #32
0
파일: UserCRUD.cs 프로젝트: tzinakos/POS
 //Create Method For Users: It Creates new Users and adds them to the User Table in the Database.
 public void Create(string userRoleName, string userName, string userPassword, DateTime startDate)
 {
     using (var db = new PosContext())
     {
         int  userRoleID = db.UserRoles.Where(u => u.UserRoleName == userRoleName).Select(x => x.UserRoleID).FirstOrDefault();
         User newUser    = new User
         {
             UserName     = userName,
             UserPassword = userPassword,
             IsActive     = true,
             StartDate    = startDate,
             UserPoints   = "0",
             UserRoleID   = userRoleID
         };
         db.Users.Add(newUser);
         db.SaveChanges();
     }
 }
예제 #33
0
 public void TestMethod1()
 {
     using (var db = new PosContext())
     {
         var barangs = db.Mst_Barangs.ToList();
         if (db.Mst_Barangs.Any())
         {
             foreach (var barang in barangs)
             {
                 Trace.WriteLine(string.Format("id:{0},Deskripsi:{1}", barang.Id, barang.Deskripsi));
             }
         }
         else
         {
             Trace.WriteLine("Data tidak tersedia");
         }
     }
 }
예제 #34
0
        public static TokoViewModel GetById(int id)
        {
            TokoViewModel result = new TokoViewModel();

            using (var db = new PosContext())
            {
                result = (from tk in db.Mst_Tokos
                          where tk.Id == id
                          select new TokoViewModel
                {
                    Id = tk.Id,
                    Nama = tk.Nama,
                    Alamat = tk.Alamat,
                    NoTelp = tk.NoTelp
                }).FirstOrDefault();
            }
            return(result);
        }
예제 #35
0
        public override string VisitPos(PosContext context)
        {
            if (context.NOUN() != null)
            {
                return(Generator.Noun);
            }
            if (context.VERB() != null)
            {
                return(Generator.Verb);
            }
            if (context.ADJECTIVE() != null)
            {
                return(Generator.Adjective);
            }

            return(context.TEXT() != null
               ? Text(context.TEXT())
               : "*gibberish*");
        }
예제 #36
0
        public static SupplierViewModel GetById(int id)
        {
            SupplierViewModel result = new SupplierViewModel();

            using (var db = new PosContext())
            {
                result = (from sup in db.Mst_Suppliers
                          where sup.Id == id
                          select new SupplierViewModel
                {
                    Id = sup.Id,
                    Nama = sup.Nama,
                    Alamat = sup.Alamat,
                    NoTelp = sup.NoTelp,
                    IsActivated = sup.IsActivated
                }).FirstOrDefault();
            }
            return(result);
        }
예제 #37
0
        public static bool Update(TokoViewModel model)
        {
            bool result = true;

            try
            {
                using (var db = new PosContext())
                {
                    if (model.Id == 0)
                    {
                        Toko toko = new Toko();
                        toko.Id          = model.Id;
                        toko.Nama        = model.Nama;
                        toko.Alamat      = model.Alamat;
                        toko.NoTelp      = model.NoTelp;
                        toko.CreatedBy   = "Rio";
                        toko.CreatedDate = DateTime.Now;
                        db.Mst_Tokos.Add(toko);
                        db.SaveChanges();
                    }
                    else
                    {
                        Toko toko = db.Mst_Tokos.Where(o => o.Id == model.Id).FirstOrDefault();
                        if (toko != null)
                        {
                            toko.Nama         = model.Nama;
                            toko.Alamat       = model.Alamat;
                            toko.NoTelp       = model.NoTelp;
                            toko.ModifiedBy   = "Rio";
                            toko.ModifiedDate = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result  = false;
                Message = ex.Message;
            }

            return(result);
        }
예제 #38
0
        public static bool DeleteById(int id)
        {
            bool result = true;

            try
            {
                using (var db = new PosContext())
                {
                    Barang barang = db.Mst_Barangs.Where(d => d.Id == id).FirstOrDefault();
                    db.Mst_Barangs.Remove(barang);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                result  = false;
                Message = ex.Message;
            }
            return(result);
        }
예제 #39
0
        public static DetailReturPenjualanViewModel GetDetailById(int id)
        {
            DetailReturPenjualanViewModel result = new DetailReturPenjualanViewModel();

            using (var db = new PosContext())
            {
                result = (from b in db.Mst_Barangs
                          where b.Id == id
                          select new DetailReturPenjualanViewModel
                {
                    IdBarang = b.Id,
                    //IdSupplier = d.IdSupplier,
                    CodeBarang = b.Code,
                    Deskripsi = b.Deskripsi,
                    //Stok = b.Stok,
                    HargaPenjualan = b.HargaPenjualan
                }).FirstOrDefault();
            }
            return(result);
        }
예제 #40
0
        public List <Product> GetProducts(int orderID)
        {
            int            id         = 0;
            List <Product> returnList = new List <Product>();

            using (var db = new PosContext())
            {
                id = (from o in db.Orders
                      where o.OrderID == orderID
                      select o.OrderID).FirstOrDefault();
            }
            foreach (var item in currentOrders)
            {
                if (item.OrderID == id)
                {
                    returnList = item.currentProducts;
                }
            }
            return(returnList);
        }
예제 #41
0
        public static DetailReceivedOrderViewModel GetDetailById(int id)
        {
            DetailReceivedOrderViewModel result = new DetailReceivedOrderViewModel();

            using (var db = new PosContext())
            {
                result = (from b in db.Mst_Barangs
                          join dbr in db.Mst_DetailBarangs
                          on b.Id equals dbr.IdBarang
                          where b.Id == id
                          select new DetailReceivedOrderViewModel
                {
                    IdBarang = b.Id,
                    //IdSupplier = d.IdSupplier,
                    CodeBarang = b.Code,
                    Deskripsi = b.Deskripsi,
                    //Stok = b.Stok,
                    HargaPembelian = dbr.HargaPembelian
                }).FirstOrDefault();
            }
            return(result);
        }
예제 #42
0
        public void CustomerInsertTest()
        {
            PosContext db          = new PosContext();
            Customer   newCustomer =
                new Customer
            {
                Name = "Test1", Address = "TestAddress", Creditlimit = 1000
            };

            db.Customer.Add(newCustomer);
            db.SaveChanges();
            //using System.Linq; //using System.Data; //using System.Data.Entity;
            Customer findCustomer =
                db.Customer.Where(C => C.Name == "Test1").FirstOrDefault();

            Assert.AreEqual(newCustomer.Name, findCustomer.Name);

            if (findCustomer != null)
            {
                db.Customer.Remove(findCustomer); // remove from Db
            }
        }
예제 #43
0
        internal static SingleUseEntity GenerateUniqueCode(string email, string userType)
        {
            Agency agency = GetCurrentUser();
            using (var ctx = new PosContext())
            {
                var model = from s in ctx.SingleUse
                            where s.email == email
                            select s;

                if (model.Any())
                {
                    var singleusecode = model.FirstOrDefault();
                    if (singleusecode != null)
                    {
                        singleusecode.SUC = Guid.NewGuid();

                        ctx.SaveChanges();

                        return singleusecode;
                    }
                }

                var suc = new SingleUseEntity
                {
                    AgencyId = agency.Id,
                    SUC = Guid.NewGuid(),
                    GeneratedCodeTime = DateTime.UtcNow,
                    email = email,
                    UserType = userType
                };

                ctx.SingleUse.Add(suc);

                ctx.SaveChanges();

                return suc;
            }
        }
예제 #44
0
        public static bool HapusBarang(DetailPenjualanViewModel model)
        {
            bool result = true;

            try
            {
                using (var db = new PosContext())
                {
                    DetailPenjualan es = db.Trans_DetailPenjualans.Where(o => o.IdHeaderPenjualan == model.IdHeaderPenjualan && o.IdBarang == model.IdBarang).FirstOrDefault();
                    if (es != null)
                    {
                        db.Trans_DetailPenjualans.Remove(es);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
                result  = false;
            }
            return(result);
        }
예제 #45
0
        public static SingleUseEntity CheckSUCValid(string guid)
        {
            try
            {

                using (var ctx = new PosContext())
                {
                    var found = ctx.SingleUse.FirstOrDefault(a => a.SUC.ToString() == guid);
                    if (found != null)
                    {
                        return found;

                    }
                    return null;//code is not found so not in db

                }

            }
            catch (Exception ex)
            {
                return null;
            }
        }
예제 #46
0
        public static BarangViewModel GetById(int id)
        {
            BarangViewModel result = new BarangViewModel();

            using (var db = new PosContext())
            {
                result = (from brg in db.Mst_Barangs
                          //join sup in db.Mst_Suppliers
                          //on brg.IdSupplier equals sup.Id
                          select new BarangViewModel
                {
                    Id = brg.Id,
                    Code = brg.Code,
                    //IdSupplier=brg.IdSupplier,
                    //NamaSupplier = sup.Nama,
                    Deskripsi = brg.Deskripsi,
                    //Harga=brg.Harga,
                    //Stok=brg.Stok,
                    IsActivated = brg.IsActivated
                }).FirstOrDefault();
            }
            return(result);
        }
예제 #47
0
        public static int CreateProperty(Property entity)
        {
            try
            {

                using (var ctx = new PosContext())
                {
                    var found = ctx.Property.FirstOrDefault(a => a.Id == entity.Id);
                    if (found == null)
                    {
                        var model = ctx.Property.Add(entity);
                        ctx.SaveChanges();
                        return model.Id;
                    }
                    return -1;

                }

            }
            catch (Exception ex)
            {
                return -1;
            }
        }
예제 #48
0
        public static Landlord AddNewLandlord(Landlord entity)
        {
            try
            {
                using (var ctx = new PosContext())

                {
                    Agency thisAgency = GlobalVariables.GetAgentsAgency;
                    AgencyLandlords AgencyLandlord = new AgencyLandlords
                    {
                        AgencyId = thisAgency.Id,
                        LandlordId = entity.Id
                    };
                    ctx.AgencyLandlords.Add(AgencyLandlord);
                    ctx.SaveChanges();
                    return (entity);
                }

            }
            catch (Exception ex)
            {
                return null;
            }
        }
예제 #49
0
        public static bool CreateAgent(Agent agent)
        {
            try
            {

                using (var ctx = new PosContext())
                {
                    var found = ctx.Agent.FirstOrDefault(a => a.UserId == agent.UserId);
                    if (found == null)
                    {
                        ctx.Agent.Add(agent);
                        ctx.SaveChanges();
                        return true;
                    }
                    return false;

                }

            }
            catch (Exception ex)
            {
                return false;
            }
        }
예제 #50
0
        public static bool InsertLogArchive(Log log)
        {
            try
            {

                using (var ctx = new PosContext())
                {
                    log.Archived = true;
                    //get email of logged on user --cast agency to user?!?!?
                    var email = GlobalVariables.CurrentUserEmail;
                    if (log != null)
                    {
                        var archive = new LogArchive
                        {
                            Log = log,
                            DateTimeArchived = DateTime.Now,
                            ArchivedByUserEmail = email
                        };
                        ctx.LogArchive.Add(archive);

                        ctx.SaveChanges();
                        return true;
                    }

                }

            }
            catch (Exception ex)
            {
                return false;
            }
            return false;
        }
예제 #51
0
        public static bool UpdateLog(Log entity)
        {
            try
            {
                using (var ctx = new PosContext())
                {

                    if (entity == null) throw new ArgumentNullException("Log not found with Id " + entity.Id);
                    InsertLogArchive(entity);
                    ctx.Entry(entity).State = EntityState.Modified;
                    ctx.SaveChanges();
                    return true;
                }

            }
            catch (Exception ex)
            {
                return false;
            }
        }
예제 #52
0
        public static List<Log> GetUserLogs(string email)
        {
            try
            {
                using (var ctx = new PosContext())
                {
                    var model = ctx.Log.Where(l => l.CreatedByEmail == email).
                        Include(l => l.Property).
                        Include(l => l.AssignedContractor).ToList();
                    return (model);
                }

            }
            catch (Exception ex)
            {
                return null;
            }
        }
예제 #53
0
        public static List<Landlord> GetAgencyLandlords(int? agencyId)
        {
            try
            {
                using (var ctx = new PosContext())
                {
                    List<Landlord> agencyLandlords = new List<Landlord>();
                    var model = ctx.AgencyLandlords.Where(l => l.AgencyId == agencyId).ToList();
                    foreach (var l in model)
                    {
                        var landlord = ctx.Landlord.FirstOrDefault(landl => landl.Id == l.LandlordId);
                        landlord.Forename = landlord.Forename + " " + landlord.Lastname;
                        agencyLandlords.Add(landlord);
                    }
                    return (agencyLandlords);
                }

            }
            catch (Exception ex)
            {
                return null;
            }
        }
예제 #54
0
        public static Agency GetAgencyById(int id)
        {
            try
            {
                using (var ctx = new PosContext())
                {
                    var model = ctx.Agency.FirstOrDefault(l => l.Id == id);
                    return model;
                }

            }
            catch (Exception ex)
            {
                return null;
            }
        }
예제 #55
0
        public static Tenant GetTenantByEmail(string email)
        {
            try
            {
                using (var ctx = new PosContext())
                {
                    var model = ctx.Tenant.FirstOrDefault(l => l.Email == email);
                    return model;
                }

            }
            catch (Exception ex)
            {
                return null;
            }
        }