Ejemplo n.º 1
0
        public ActionResult Create(vendorModel user)
        {
            using (var context = new promoLacDbEntities())
            {
                {
                    vendor info = new vendor()
                    {
                        firstName         = user.firstName,
                        lastName          = user.lastName,
                        vendorEmail       = user.vendorEmail,
                        vendorPassword    = user.vendorPassword,
                        registerTimestamp = DateTime.Now,
                        phoneNumber       = user.phoneNumber,
                        vendorUserName    = user.vendorUserName,
                        headId            = vendorId(User.Identity.Name),
                        isHead            = "N",
                        vendorStatus      = "A",
                        vendorAddress     = vendorAddress(vendorId(User.Identity.Name)),
                        vendorCompanyName = vendorCompanyName(vendorId(User.Identity.Name))
                    };


                    context.vendors.Add(info);
                    context.SaveChanges();
                    var         result = context.userPackages.Where(x => x.vendorId == info.headId).FirstOrDefault();
                    userPackage u      = new userPackage();
                    u.vendorId               = vendorId(user.vendorUserName);
                    u.packageStartTime       = result.packageStartTime;
                    u.packageEndTime         = result.packageEndTime;
                    u.packageId              = result.packageId;
                    u.dividedShareOfMessages = user.messagesAllowed;
                    u.packageStatus          = "active";
                    u.notificationSent       = 0;
                    u.remainingFencingHours  = user.fencingHours;
                    context.userPackages.Add(u);
                    context.SaveChanges();

                    foreach (var x in user.areas)
                    {
                        areaAssigned ar = new areaAssigned()
                        {
                            vendorId = vendorId(user.vendorUserName),
                            areaId   = Convert.ToInt32(x)
                        };
                        context.areaAssigneds.Add(ar);
                        context.SaveChanges();
                    }
                    var result1 = context.userPackages.Where(x => x.vendorId == info.headId).FirstOrDefault();
                    result1.dividedShareOfMessages = result1.dividedShareOfMessages - user.messagesAllowed;
                    result1.remainingFencingHours  = result1.remainingFencingHours - user.fencingHours;
                    context.SaveChanges();
                }


                return(RedirectToAction("../ControlPanel/ControlPanel"));
            }
        }
Ejemplo n.º 2
0
        // GET: controlPanel
        public ActionResult controlPanel()
        {
            using (var context = new promoLacDbEntities())
            {
                int         id = vendorId(User.Identity.Name);
                userPackage d  = new userPackage();

                var result = context.userPackages.Where(x => x.vendorId == id).Select(x => new userPackageModel()
                {
                    notificationSent       = x.notificationSent,
                    packageId              = x.packageId,
                    dividedShareOfMessages = x.dividedShareOfMessages,
                    messagesRemaining      = x.dividedShareOfMessages - x.notificationSent,
                    remainingFencingHours  = x.remainingFencingHours
                }).FirstOrDefault();

                /*d.messagesSent = result.messagesSent;
                 * d.messagesAllowed = messagesAllowed(result.packageId);
                 * d.messagesRemaining = d.messagesAllowed-d.messagesSent;
                 *
                 */
                var result1 = context.vendors.Where(x => x.vendorId == id).First();
                List <DataPoint> dataPointsNot = new List <DataPoint>();
                DateTime         time          = result1.registerTimestamp;

                int y     = DateTime.Compare(time, DateTime.Now);
                int count = 0;
                while (y != 1)
                {
                    var dt = time.Date;
                    var z  = context.notifications.Where(a => (a.vendorId == id) && (a.notificationTime == dt)).Count();
                    dataPointsNot.Add(new DataPoint(count, z));
                    time = time.AddDays(1);
                    y    = DateTime.Compare(time.Date, DateTime.Now.Date);
                    count++;
                }

                ViewData["name"] = "Inam";
                ViewBag.DataPointsNotification = JsonConvert.SerializeObject(dataPointsNot);


                List <DataPoint> dataPointsDeal = new List <DataPoint>();
                time  = result1.registerTimestamp;
                count = 0;
                y     = DateTime.Compare(time, DateTime.Now);
                while (y != 1)
                {
                    var dt = time.Date;
                    var z  = context.deals.Where(a => (a.vendorId == id) && (a.dealTime == dt)).Count();
                    dataPointsDeal.Add(new DataPoint(count, z));
                    time = time.AddDays(1);
                    y    = DateTime.Compare(time.Date, DateTime.Now.Date);
                    count++;
                }
                ViewData["name"]       = "Inam";
                ViewBag.DataPointsDeal = JsonConvert.SerializeObject(dataPointsDeal);
                List <DataPoint> dataPointsFence = new List <DataPoint>();
                time  = result1.registerTimestamp;
                count = 0;
                y     = DateTime.Compare(time, DateTime.Now);
                while (y != 1)
                {
                    var dt = time.Date;
                    var z  = context.fences.Where(a => (a.vendorId == id) && (DbFunctions.TruncateTime(a.startTime) == dt)).Count();
                    dataPointsFence.Add(new DataPoint(count, z));
                    time = time.AddDays(1);
                    y    = DateTime.Compare(time.Date, DateTime.Now.Date);
                    count++;
                }
                ViewData["name"]        = "Inam";
                ViewBag.DataPointsFence = JsonConvert.SerializeObject(dataPointsFence);


                return(View(result));
            }
        }