示例#1
0
        public ActionResult UpdateRole(RoleModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    using (var db = new eXmlContext())
                    {
                        var role = db.Set <Role>()
                                   .SingleOrDefault(x => x.RoleId == model.RoleId);

                        role.RoleName = model.RoleName;
                        role.RoleType = model.RoleType;

                        db.Entry(role).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please correct all errors";
                ViewData["Role"]      = model;
            }
            return(PartialView("_GridListRoles", AdminServiceProvider.Roles()));
        }
示例#2
0
        public ActionResult UpdateUser(UserModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    using (var db = new eXmlContext())
                    {
                        var user = db.Set <User>()
                                   .SingleOrDefault(x => x.UserId == model.UserId);

                        user.Email      = model.Email;
                        user.Password   = model.Password;
                        user.IsLicensed = model.IsLicensed;
                        user.ExpiryDate = model.ExpiryDate;

                        db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please correct all errors";
                ViewData["User"]      = model;
            }
            return(PartialView("_GridListUsers", AdminServiceProvider.Users()));
        }
示例#3
0
 public ActionResult AddRole(RoleModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             Role r = new Role
             {
                 RoleName = model.RoleName,
                 RoleType = model.RoleType
             };
             using (var db = new eXmlContext())
             {
                 db.Roles.Add(r);
                 db.SaveChanges();
             }
         }
         catch (Exception e)
         {
             ViewData["EditError"] = e.Message;
         }
     }
     else
     {
         ViewData["EditError"] = "Please correct all errors";
         ViewData["Role"]      = model;
     }
     return(PartialView("_GridListRoles", AdminServiceProvider.Roles()));
 }
示例#4
0
 public ActionResult SetRole(RolesCheckBoxListEditModel model)
 {
     using (var db = new eXmlContext())
     {
         User user = db.Users.Find(model.Id);
         user.Roles.UpdateRoleCollectionFromModel(db.Roles, model.RoleIds);
         db.SaveChanges();
     }
     ViewData["Message"] = "Roles for this user have been set successfully!";
     return(RedirectToAction("SetRole", new { userId = model.Id }));
 }
示例#5
0
        public ActionResult AddUser(UserModel model)
        {
            if (ModelState.IsValid)
            {
                string cryptoKey = ConfigurationManager.AppSettings["CryptoKey"].ToString();
                Crypto.Key = cryptoKey;
                Crypto.EncryptionAlgorithm = Crypto.Algorithm.DES;

                try
                {
                    string encryptPwd = "";
                    if (Crypto.EncryptString(model.Password))
                    {
                        encryptPwd = Crypto.Content;
                    }
                    User u = new User
                    {
                        Email      = model.Email,
                        Password   = encryptPwd,
                        IsLicensed = model.IsLicensed,
                        ExpiryDate = model.ExpiryDate
                    };

                    using (var db = new eXmlContext())
                    {
                        db.Users.Add(u);
                        db.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }

            else
            {
                ViewData["EditError"] = "Please correct all errors";
                ViewData["User"]      = model;
            }
            return(PartialView("_GridListUsers", AdminServiceProvider.Users()));
        }
示例#6
0
        public string UpdateUserMainMenuXml(int userId)
        {
            bool   isAdmin = false;
            string userFile;

            using (var db = new eXmlContext())
            {
                User user = db.Set <User>().Where(x => x.UserId == userId).First();

                foreach (var role in user.Roles)
                {
                    //check if user has admin role
                    if (role.RoleType == enRoleType.Admin)
                    {
                        isAdmin = true;
                    }
                }
                string        fileName = Path.Combine(Server.MapPath("~/App_Data"), "main.xml");
                XmlTextReader reader   = new XmlTextReader(fileName);
                XmlDocument   doc      = new XmlDocument();
                doc.Load(reader);

                reader.Close();

                XmlNode    adminNode;
                XmlElement root = doc.DocumentElement;
                userFile = "newmenu.xml";
                string userFilePath = Path.Combine(Server.MapPath("~/App_Data"), userFile);
                if (isAdmin == false) // remove admin child node
                {
                    adminNode = root.SelectSingleNode("/mainmenu/item[@Role='Admin']");
                    root.RemoveChild(adminNode);
                    doc.Save(userFilePath);
                }
                else
                {
                    doc.Save(userFilePath);
                }
            }
            return(userFile);
        }
示例#7
0
        public ActionResult PaymentBulk(string selectedIDsHF)
        {
            char[] array = new Char[1];
            array[0] = Char.Parse(",");

            string[] orderIds  = selectedIDsHF.Split(array);
            int      response  = 0;
            DateTime invDate   = DateTime.Now.AddMonths(-1);
            DateTime invDateTo = DateTime.Now;

            foreach (var orderId in orderIds)
            {
                using (var dbContext = new eXmlContext())
                {
                    int id = int.Parse(orderId);
                    IEnumerable <PostedTransaction> pTrans = dbContext.Set <PostedTransaction>()
                                                             .Where(x => x.OrderId == id)
                                                             .ToList();
                    if (pTrans != null)
                    {
                        decimal totalAmtPayable;
                        foreach (var trans in pTrans)
                        {
                            totalAmtPayable     = (trans.ConsultantPrice * trans.OrderQty) - trans.PaymentAmount;
                            trans.PaymentAmount = totalAmtPayable + trans.PaymentAmount;
                            trans.PaymentDate   = DateTime.Now;
                            trans.PaymentType   = enPaymentType.Cash;
                            trans.PayStatus     = enPaymentStatus.Received;

                            dbContext.Entry(trans).State = System.Data.Entity.EntityState.Modified;
                        }
                        dbContext.SaveChanges();
                        response = 1;
                    }
                }
            }
            ViewData["PayType"]    = EnumHelper.ToList(typeof(enPaymentType));
            ViewData["Assemblies"] = TransactionProvider.LoadAssemblies();
            //return PartialView("_GridListInvoices", TransactionProvider.InvoiceEditableTransactions(null, null, null, null));
            return(Json(response));
        }
示例#8
0
        public ActionResult SetRole(int userId)
        {
            var model = new RolesCheckBoxListEditModel();

            using (var db = new eXmlContext())
            {
                User user;
                user = db.Set <User>().FirstOrDefault(x => x.UserId == userId);
                var allRoles = db.Set <Role>().ToList();
                if (user != null)
                {
                    IEnumerable <SelectListItem> listRoles = user.Roles.ToCheckBoxRolesListSource(allRoles);
                    for (var i = 0; i < allRoles.Count(); i++)
                    {
                        listRoles.ElementAt(i).Text = allRoles.ElementAt <Role>(i).RoleName;
                    }
                    model.Roles = listRoles;
                    model.Id    = user.UserId;
                }
            }
            return(View(model));
        }
示例#9
0
        public ActionResult PaymentUpdate(ListInvoiceTransModel trans)
        {
            string   assembly = "";
            string   unit     = "";
            DateTime invDate  = DateTime.Now;

            if (trans.Id > 0 && trans.PaymentType != null && trans.PaymentDate != null)
            {
                try
                {
                    int Id = trans.Id;
                    using (var db = new eXmlContext())
                    {
                        IEnumerable <PostedTransaction> pTrans = db.Set <PostedTransaction>()
                                                                 .Where(x => x.OrderId == Id)
                                                                 .ToList();
                        if (pTrans != null)
                        {
                            assembly = pTrans.First().AssemblyName;
                            unit     = pTrans.First().UnitName;
                            invDate  = pTrans.First().PostDate;
                            //invDate = pTrans.First().InvoiceDate;
                            //get total net amount payable as per order id
                            decimal netAmtPayable = 0;
                            decimal amtPaid       = 0;
                            foreach (var tr in pTrans)
                            {
                                netAmtPayable = netAmtPayable + tr.NetAmount + tr.VatAmount;
                                amtPaid       = amtPaid + tr.PaymentAmount;
                            }
                            netAmtPayable = netAmtPayable - amtPaid;
                            if (trans.PaymentAmount <= netAmtPayable)
                            {
                                decimal balAfterDeduct = trans.PaymentAmount;
                                decimal totalAmtPayable;
                                foreach (var transaction in pTrans)
                                {
                                    totalAmtPayable = (transaction.ConsultantPrice * transaction.OrderQty) - transaction.PaymentAmount;

                                    transaction.PaymentDate = trans.PaymentDate;
                                    transaction.PaymentType = trans.PaymentType;
                                    transaction.BankName    = trans.BankName;
                                    transaction.ChequeNo    = trans.ChequeNo;

                                    if (balAfterDeduct >= totalAmtPayable && totalAmtPayable > 0)
                                    {
                                        transaction.PaymentAmount = transaction.PaymentAmount + totalAmtPayable;
                                        transaction.PayStatus     = enPaymentStatus.Received;
                                        balAfterDeduct            = balAfterDeduct - totalAmtPayable;
                                    }
                                    else if (balAfterDeduct > 0 && balAfterDeduct < totalAmtPayable)
                                    {
                                        transaction.PaymentAmount = transaction.PaymentAmount + balAfterDeduct;
                                        transaction.PayStatus     = enPaymentStatus.Partial;

                                        balAfterDeduct = 0;
                                    }
                                    else
                                    {
                                        transaction.PaymentAmount = transaction.PaymentAmount;
                                        transaction.PayStatus     = enPaymentStatus.Pending;
                                    }
                                    db.Entry(transaction).State = System.Data.Entity.EntityState.Modified;
                                }
                                db.SaveChanges();
                            }
                            else
                            {
                                ViewData["EditError"] = "Payment amount is greater than net amount payable!";
                            }
                        }
                        else
                        {
                            ViewData["EditError"] = "Posted transaction object is null. Unable to obtain transaction from Db";
                        }
                    }
                }
                catch (Exception ex)
                {
                    ViewData["EditError"] = ex.Message;
                }
            }
            else
            {
                ViewData["PostedTrans"] = trans;
                ViewData["EditError"]   = "Payment type and payment date cannot contain null values! Enter values and update!";
            }

            return(PartialView("_GridListInvoices", TransactionProvider.InvoiceEditableTransactions(assembly, unit, invDate, invDate)));
        }
示例#10
0
        private void UpdatePurchaseRegister(Invoice invoice, string company, string dbShip,
                                            DateTime fromDate, DateTime toDate)
        {
            try
            {
                using (var db = new eXmlContext())
                {
                    foreach (var invItem in invoice.Items)
                    {
                        var purRecExists = db.Set <PurchaseRegister>()
                                           .Where(x => x.Company == company && x.DbShip == dbShip)
                                           .Where(x => x.InvoiceNo == invoice.InvoiceNo)
                                           .Where(x => x.InvoiceType == invoice.InvoiceType)
                                           .Where(x => x.ItemCode == invItem.ItemCode)
                                           .Where(x => x.PaymentInstrument == invItem.PaymentInstrument)
                                           .Where(x => x.OrdYearWk == invoice.OrdYearWk && x.InvYearWk == invoice.InvYearWk)
                                           .FirstOrDefault();
                        if (purRecExists == null)
                        {
                            PurchaseRegister reg = new PurchaseRegister
                            {
                                Company           = company,
                                DbShip            = dbShip,
                                FromDate          = fromDate,
                                ToDate            = toDate,
                                ItemCode          = invItem.ItemCode,
                                PaymentInstrument = invItem.PaymentInstrument,
                                ItemName          = invItem.ItemName,
                                OrdYearWk         = invoice.OrdYearWk,
                                InvoiceNo         = invoice.InvoiceNo,
                                InvoiceType       = invoice.InvoiceType,
                                InvoiceDate       = invoice.InvoiceDate,
                                InvYearWk         = invoice.InvYearWk,
                                Quantity          = invItem.Quantity,
                                PriceWOTax        = invItem.PriceWOTax,
                                VAT          = invItem.VAT,
                                PriceInclVAT = invItem.PriceInclVAT
                            };
                            db.PurchaseRegister.Add(reg);
                        }
                        else
                        {
                            purRecExists.Company           = company;
                            purRecExists.DbShip            = dbShip;
                            purRecExists.FromDate          = fromDate;
                            purRecExists.ToDate            = toDate;
                            purRecExists.ItemCode          = invItem.ItemCode;
                            purRecExists.PaymentInstrument = invItem.PaymentInstrument;
                            purRecExists.ItemName          = invItem.ItemName;
                            purRecExists.OrdYearWk         = invoice.OrdYearWk;
                            purRecExists.InvoiceNo         = invoice.InvoiceNo;
                            purRecExists.InvoiceType       = invoice.InvoiceType;
                            purRecExists.InvoiceDate       = invoice.InvoiceDate;
                            purRecExists.InvYearWk         = invoice.InvYearWk;
                            purRecExists.Quantity          = invItem.Quantity;
                            purRecExists.PriceWOTax        = invItem.PriceWOTax;
                            purRecExists.VAT          = invItem.VAT;
                            purRecExists.PriceInclVAT = invItem.PriceInclVAT;

                            db.Entry(purRecExists).State = EntityState.Modified;
                        }
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }