Beispiel #1
0
        public ActionResult NewCommend(String description, int ticketID, HttpPostedFileBase file)
        {
            try
            {
                SSMEntities se = new SSMEntities();

                if (file != null)
                {
                    TicketFile ticketFile = new TicketFile();

                    Storage storeage = new Storage();
                    ticketFile.Url      = storeage.uploadMyfile("ticket" + ticketID, "file" + ticketID, file);
                    ticketFile.FileName = file.FileName;
                    se.TicketFiles.Add(ticketFile);
                    ticketFile.TicketID = ticketID;
                    se.SaveChanges();
                }

                TicketComment commend = new TicketComment();
                commend.Creator     = User.Identity.GetUserId();
                commend.Description = description;
                commend.createddate = DateTime.Today;
                commend.point       = 1;
                commend.ticketID    = ticketID;
                commend.Accepted    = false;

                se.TicketComments.Add(commend);
                se.SaveChanges();
                return(RedirectToAction("Detail", new { id = ticketID }));
            }
            catch (Exception e) { }


            return(RedirectToAction("Index"));
        }
Beispiel #2
0
 public void deleteCalendarByUserID(String userid)
 {
     try
     {
         List <MasterSchedule_User> lst = context.MasterSchedule_User.SqlQuery("SELECT * FROM MasterSchedule_User where userID='" + userid + "'").ToList();
         context.MasterSchedule_User.RemoveRange(lst);
         context.SaveChanges();
     }
     catch (Exception e) {
     }
 }
Beispiel #3
0
        public ActionResult CreateNewProgress(FollowupProgressModel model)
        {
            PrePurchase_FollowUp_Plan plan = new PrePurchase_FollowUp_Plan();

            plan.Description = model.Desription;
            plan.name        = model.Name;
            plan.isActive    = true;
            plan.isOperation = false;
            plan.productID   = model.productID;

            plan.createDate = DateTime.Today;

            SSMEntities se = new SSMEntities();

            se.PrePurchase_FollowUp_Plan.Add(plan);
            se.SaveChanges();

            foreach (Plan_Step step in model.steps.ToList())
            {
                if (step.StepEmailContent == null)
                {
                    model.steps.Remove(step);
                }
                else if (step.StepEmailContent.Trim().Length == 0)
                {
                    model.steps.Remove(step);
                }
            }
            for (int i = 0; i < model.steps.Count(); i++)
            {
                Plan_Step step = model.steps[i];
                step.stepNo = (i + 1);
                step.planID = plan.id;
                se.Plan_Step.Add(step);
                se.SaveChanges();
            }
            for (int i = 0; i < model.steps.Count(); i++)
            {
                Plan_Step step = model.steps[i];
                if (i != 0)
                {
                    step.previousStep = model.steps[i - 1].id;
                }
                if (i != model.steps.Count() - 1)
                {
                    step.nextStep = model.steps[i + 1].id;
                }
                se.SaveChanges();
            }

            return(RedirectToAction("Detail", new { id = model.productID }));
        }
Beispiel #4
0
        public void CreateNewEmailTemplate(EmailTemplateEntity template)
        {
            var dbTemplate = new Email_Template();

            dbTemplate.isActive    = template.isActive;
            dbTemplate.lastUpdate  = template.lastUpdate;
            dbTemplate.MailContent = template.MailContent;
            dbTemplate.Name        = template.Name;
            dbTemplate.CateID      = template.EmailCategoryId;
            dbTemplate.createdDate = template.createdDate;
            dbTemplate.creatorID   = template.creatorID;
            context.Email_Template.Add(dbTemplate);
            context.SaveChanges();
        }
Beispiel #5
0
        public void DealWon(int id, String userID)
        {
            SSMEntities    se       = new SSMEntities();
            DealRepository dealrepo = new DealRepository(se);
            Deal           deal     = dealrepo.getByID(id);

            if (deal != null)
            {
                deal.Status = 3;

                customer cus = new customer();
                cus.userID     = userID;
                cus.cusAddress = deal.contact.Street + " " + deal.contact.City + " " + deal.contact.Region + " ";
                cus.cusCompany = 1;
                cus.cusEmail   = deal.contact.emails;
                cus.cusName    = deal.contact.FirstName + " " + deal.contact.MiddleName + " " + deal.contact.LastName;
                cus.cusPhone   = deal.contact.Phone;
                se.customers.Add(cus);
                se.SaveChanges();
                try {
                    order order = new order();
                    order.customerID = cus.id;
                    float price = 0;
                    order.orderNumber = 123123123;
                    order.subtotal    = deal.Value;
                    order.status      = 1;
                    order.total       = (double)order.subtotal * 1.1;
                    order.VAT         = (double)order.subtotal * 0.1;
                    Storage storeage = new Storage();

                    se.orders.Add(order);
                    se.SaveChanges();
                    order.Contract = storeage.uploadfile(userID, "order" + order.id);
                    se.SaveChanges();
                    MarketPlanPurchased mp = new MarketPlanPurchased();
                    mp.orderID   = order.id;
                    mp.planID    = deal.productMarketPlan.id;
                    mp.productID = deal.productMarketPlan.productID;

                    mp.SoldPrice = (double)deal.Value;
                    mp.quantity  = deal.Quantity;
                    se.MarketPlanPurchaseds.Add(mp);
                    se.SaveChanges();
                    deal.Status = 5; se.SaveChanges();
                }
                catch (Exception e) {
                }
            }
        }
Beispiel #6
0
        public ActionResult CreateDeal(Deal deal, int plan)
        {
            SSMEntities se = new SSMEntities();

            deal.planID          = plan;
            deal.Creator         = User.Identity.GetUserId();
            deal.StartDate       = DateTime.Today;
            deal.Stage           = 1;
            deal.Probability     = 0;
            deal.CompleteOn      = null;
            deal.LastUpdateStage = null;
            deal.Status          = 1;

            se.Deals.Add(deal);
            se.SaveChanges();
            contact contact = se.contacts.Find(deal.Client);
            int     day     = 0;

            if (contact != null)
            {
                foreach (Plan_Step tep in se.PrePurchase_FollowUp_Plan.Find(plan).Plan_Step)
                {
                    if (tep.TimeFromLastStep == null)
                    {
                        tep.TimeFromLastStep = 0;
                    }
                    day = day + (int)tep.TimeFromLastStep;
                    DealTask task = new DealTask();
                    task.dealID          = deal.id;
                    task.TaskDescription = tep.StepEmailContent;

                    task.status = 1;
                    if (tep.RequireMoreDetail)
                    {
                        task.status = 7;
                    }
                    task.Deadline    = DateTime.Today.AddDays(day);
                    task.CreateDate  = DateTime.Today;
                    task.TaskContent = tep.subject;
                    task.TaskName    = "Progress";
                    task.type        = 8;
                    se.DealTasks.Add(task);
                    se.SaveChanges();
                }
            }


            return(RedirectToAction("Detail", new { id = deal.id }));
        }
Beispiel #7
0
        public ActionResult makenewRequest(int planID, String firstname, String lastname, String email, String businessname, String BussinessAddress, String website, String role, String description, String dates)
        {
            System.Diagnostics.Debug.WriteLine("em ay day " + dates);
            SSMEntities       se   = new SSMEntities();
            productMarketPlan plan = se.productMarketPlans.Find(planID);
            contact           con  = new contact();

            con.FirstName   = firstname;
            con.MiddleName  = " ";
            con.Phone       = "Not available";
            con.Photo       = "Not available";
            con.DateOfBirth = DateTime.Today;
            con.Street      = BussinessAddress;
            con.LastName    = lastname;
            con.emails      = email;
            con.Comment     = description;
            company com = new company();

            com.companyName = businessname;
            com.Street      = BussinessAddress;
            com.logo        = "Not available";
            com.sites       = website;
            se.companies.Add(com);
            se.SaveChanges();
            con.CompanyID = com.id;
            se.contacts.Add(con);
            se.SaveChanges();
            Customer_Request request = new Customer_Request();

            request.RequestNo      = con.id + "" + com.id + "";
            request.PlanID         = planID;
            request.ProductID      = plan.softwareProduct.id;
            request.CusID          = con.id;
            request.CreatedDate    = DateTime.Today;
            request.RequestDemoDay = dates;
            se.Customer_Request.Add(request);
            se.SaveChanges();
            Notification noti = new Notification();

            noti.NotiName    = "New Request";
            noti.NotiContent = con.FirstName + " " + "has new request for " + plan.softwareProduct.name;
            noti.userID      = "3d23016d-074f-474e-a6b7-225de90b0cae";
            noti.CreateDate  = DateTime.Now;
            noti.viewed      = false;
            noti.hreflink    = "/Request/";
            se.Notifications.Add(noti);
            se.SaveChanges();
            return(View("Success"));
        }
Beispiel #8
0
 public ActionResult CreateNewProfile(ProfileModel model)
 {
     if (ModelState.IsValid)
     {
         AccountController ac  = new AccountController();
         String            id  = ac.RegisterNewAccount(model.username, model.password, System.Web.HttpContext.Current, "SalesRep");
         SaleRepProfile    srp = new SaleRepProfile();
         srp.userID    = id;
         srp.FirstName = model.firstname;
         srp.LastName  = model.lastname;
         srp.FullName  = model.firstname + " " + model.fullname + " " + model.lastname;
         srp.Email     = model.email;
         srp.City      = model.city;
         srp.Phone     = model.phone;
         Storage storeage = new Storage();
         srp.Avatar        = storeage.uploadMyfile(id, "avatar", model.avatar);
         srp.EmployedScine = DateTime.Today;
         srp.Country       = model.country;
         srp.dateOfBirth   = model.birthday;
         SSMEntities se = new SSMEntities();
         se.SaleRepProfiles.Add(srp);
         se.SaveChanges();
         return(RedirectToAction("Detail", new { id = id }));
     }
     return(RedirectToAction("NewProfile"));
 }
Beispiel #9
0
        public ActionResult AddItemToDeal(int planID, float suggestprice, int quantity, int dealID)
        {
            SSMEntities se   = new SSMEntities();
            Deal        deal = se.Deals.Find(dealID);

            if (deal != null)
            {
                Deal_Item item = new Deal_Item();
                item.planID   = planID;
                item.dealID   = dealID;
                item.price    = suggestprice;
                item.Quantity = quantity;
                if (deal.Value == null)
                {
                    deal.Value = suggestprice * quantity;
                }
                else
                {
                    deal.Value = deal.Value + suggestprice * quantity;
                }
                se.Deal_Item.Add(item);
                se.SaveChanges();
            }
            return(RedirectToAction("Detail", new { id = dealID }));
        }
Beispiel #10
0
        public ActionResult UpdateMail(string username, string password)
        {
            SSMEntities se = new SSMEntities();

            se.ConfigureSys.Where(u => u.id == 1).First().value = username + "";
            se.ConfigureSys.Where(u => u.id == 2).First().value = password + "";
            se.SaveChanges();
            return(RedirectToAction("SystemConfig"));
        }
Beispiel #11
0
        public void CreateNewContact(contact cont, String responsible)
        {
            string[] stringSeparators = new string[] { ";" };
            String[] salerepid        = responsible.Split(stringSeparators, StringSplitOptions.None);

            context.contacts.Add(cont);
            context.SaveChanges();
            for (int i = 0; i < salerepid.Length; i++)
            {
                try {
                    contact_resposible cr = new contact_resposible();
                    cr.contactID = cont.id;
                    cr.userID    = salerepid[i];
                    context.contact_resposible.Add(cr);
                }
                catch (Exception e) { }
            }
            context.SaveChanges();
        }
Beispiel #12
0
        public ActionResult UdpateMetric(int sc, int act, int ncm, int wr, int asv)
        {
            SSMEntities se = new SSMEntities();

            se.ConfigureSys.Where(u => u.id == 15).First().value = sc + "";
            se.ConfigureSys.Where(u => u.id == 16).First().value = act + "";
            se.ConfigureSys.Where(u => u.id == 17).First().value = ncm + "";
            se.ConfigureSys.Where(u => u.id == 19).First().value = wr + "";
            se.ConfigureSys.Where(u => u.id == 20).First().value = asv + "";
            se.SaveChanges();
            return(RedirectToAction("SystemConfig"));
        }
Beispiel #13
0
        public ActionResult LicenseImport(HttpPostedFileBase excelfile, int planID)
        {
            SSMEntities se = new SSMEntities();

            if (excelfile == null || excelfile.ContentLength == 0)
            {
                ViewBag.Error = "Please select an Excel file<br>";
                return(View("Index"));
            }
            else
            {
                if (excelfile.FileName.EndsWith("xls") || excelfile.FileName.EndsWith("xlsx"))
                {
                    string path = Server.MapPath("~/Content/" + excelfile.FileName);
                    System.Diagnostics.Debug.WriteLine("noa ne: " + path);
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }
                    excelfile.SaveAs(path);
                    // Read data from excel file
                    Excel.Application   application  = new Excel.Application();
                    Excel.Workbook      workbook     = application.Workbooks.Open(path);
                    Excel.Worksheet     worksheet    = workbook.ActiveSheet;
                    Excel.Range         range        = worksheet.UsedRange;
                    List <TrialAccount> listAccounts = new List <TrialAccount>();
                    // row = 3 is the row data begin with - 1
                    for (int row = 3; row <= range.Rows.Count; row++)
                    {
                        License lic = new License();
                        lic.LicenseKey      = ((Excel.Range)range.Cells[row, 1]).Text;
                        lic.PlanID          = planID;
                        lic.licenseDuration = ((Excel.Range)range.Cells[row, 2]).Text;
                        lic.LinkUse         = ((Excel.Range)range.Cells[row, 3]).Text;
                        lic.AdminAccount    = ((Excel.Range)range.Cells[row, 4]).Text;
                        lic.AdminPassword   = ((Excel.Range)range.Cells[row, 5]).Text;
                        //account.PlanID = int.Parse(((Excel.Range)range.Cells[row, 3]).Text);
                        //DateTime createdDate = Convert.ToDateTime(((Excel.Range)range.Cells[row, 4]).Text);
                        //account.createdDate = createdDate;
                        se.Licenses.Add(lic);
                    }
                    application.Workbooks.Close();
                    se.SaveChanges();

                    return(RedirectToAction("MarketPlanDetail", new { id = planID }));
                }
                else
                {
                    return(RedirectToAction("MarketPlanDetail", new { id = planID }));
                }
            }
        }
Beispiel #14
0
        public ActionResult NewTrialAccount(String username, String password, int planID)
        {
            SSMEntities  se    = new SSMEntities();
            TrialAccount trail = new TrialAccount();

            trail.UserName = username;
            trail.Password = password;
            trail.PlanID   = planID;
            trail.Status   = 1;
            se.TrialAccounts.Add(trail);
            se.SaveChanges();
            return(RedirectToAction("MarketPlanDetail", new { id = planID }));
        }
Beispiel #15
0
        public JsonResult viewedNotification(int id)
        {
            SSMEntities  se   = new SSMEntities();
            Notification noti = se.Notifications.Find(id);

            if (noti != null)
            {
                noti.viewed = true;
                se.SaveChanges();
                return(Json(new { succeed = noti.hreflink }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { ffail = "fail" }, JsonRequestBehavior.AllowGet));
        }
Beispiel #16
0
        public ActionResult NewLicense(String key, int duration, int planID, String url, String adminaccount, string adminpassword)
        {
            SSMEntities se  = new SSMEntities();
            License     lic = new License();

            lic.PlanID          = planID;
            lic.licenseDuration = duration;
            lic.LicenseKey      = key;
            lic.LinkUse         = url;
            lic.AdminAccount    = adminaccount;
            lic.AdminPassword   = adminpassword;
            se.Licenses.Add(lic);
            se.SaveChanges();
            return(RedirectToAction("MarketPlanDetail", new { id = planID }));
        }
Beispiel #17
0
 public JsonResult MarketPlanSwitchStatus(int id)
 {
     try
     {
         SSMEntities       se     = new SSMEntities();
         productMarketPlan myplan = se.productMarketPlans.Find(id);
         myplan.operating = !myplan.operating;
         se.SaveChanges();
         return(Json(new { result = "succeed" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception e)
     {
     }
     return(Json(new { result = "fail" }, JsonRequestBehavior.AllowGet));
 }
Beispiel #18
0
        public JsonResult paid(float money, int commisionID)
        {
            SSMEntities      se  = new SSMEntities();
            SaleRepCommision com = se.SaleRepCommisions.Find(commisionID);

            if (com != null)
            {
                if (money > 0)
                {
                    com.Paid = com.Paid + money;
                    se.SaveChanges();
                    return(Json(new { result = "true", paid = ((double)com.Paid).ToString("C"), percentage = com.Paid * 100 / com.Total }, JsonRequestBehavior.AllowGet));
                }
            }
            return(null);
        }
Beispiel #19
0
        public ActionResult SetInactiveMarketPlan(int planid, int productID)
        {
            try
            {
                SSMEntities       se   = new SSMEntities();
                productMarketPlan plan = se.productMarketPlans.Find(planid);
                plan.isActive = false;
                se.SaveChanges();
                System.Diagnostics.Debug.WriteLine("cccccccc " + productID);
                return(RedirectToAction("Detail", new { id = productID }));
            }
            catch (Exception e)
            {
            }

            return(RedirectToAction("Index"));
        }
Beispiel #20
0
        public ActionResult Newticket(String title, int serverity, int category, String description)
        {
            Ticket tick = new Ticket();

            tick.Creator         = User.Identity.GetUserId();
            tick.CreatedDay      = DateTime.Today;
            tick.Description     = description;
            tick.TicketCategory  = category;
            tick.TicketServerity = serverity;
            tick.TicketName      = title;
            tick.TicketStatus    = 1;
            tick.ViewCounted     = 0;
            SSMEntities se = new SSMEntities();

            se.Tickets.Add(tick);
            se.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #21
0
        public JsonResult EditPlanMail(int taskid, String newcontent)
        {
            SSMEntities se   = new SSMEntities();
            DealTask    task = se.DealTasks.Find(taskid);

            try
            {
                if (task != null)
                {
                    task.TaskDescription = newcontent;
                    task.status          = 1;
                    se.SaveChanges();
                    return(Json(new { result = "success" }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e) { }

            return(Json(new { result = "fail" }, JsonRequestBehavior.AllowGet));
        }
Beispiel #22
0
        public JsonResult SendEarlyMail(int mailid)
        {
            SSMEntities se   = new SSMEntities();
            DealTask    task = se.DealTasks.Find(mailid);

            if (task != null)
            {
                if (task.Deal.Stage + 1 < (int.Parse(task.TaskContent)))
                {
                    return(Json(new { sentresult = "fail" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    task.Deadline = DateTime.Now;
                    se.SaveChanges();
                    return(Json(new { sentresult = "suceed" }, JsonRequestBehavior.AllowGet));
                }
            }
            return(Json(new { sentresult = "fail" }, JsonRequestBehavior.AllowGet));
        }
Beispiel #23
0
        public ActionResult UpdateKeyword(String fn, string pn, string mdd, string mt, string lk, string news, string pf, string cc, string links, string username, string password)
        {
            SSMEntities se = new SSMEntities();

            se.ConfigureSys.Where(u => u.id == 3).First().value  = fn + "";
            se.ConfigureSys.Where(u => u.id == 4).First().value  = pn + "";
            se.ConfigureSys.Where(u => u.id == 5).First().value  = mdd + "";
            se.ConfigureSys.Where(u => u.id == 7).First().value  = mt + "";
            se.ConfigureSys.Where(u => u.id == 8).First().value  = lk + "";
            se.ConfigureSys.Where(u => u.id == 9).First().value  = news + "";
            se.ConfigureSys.Where(u => u.id == 10).First().value = pf + "";
            se.ConfigureSys.Where(u => u.id == 11).First().value = cc + "";
            se.ConfigureSys.Where(u => u.id == 12).First().value = links + "";
            se.ConfigureSys.Where(u => u.id == 13).First().value = username + "";
            se.ConfigureSys.Where(u => u.id == 14).First().value = password + "";

            se.SaveChanges();

            return(RedirectToAction("SystemConfig"));
        }
Beispiel #24
0
        public ActionResult NewEmail(String mailcontent, int dealID)
        {
            SSMEntities se   = new SSMEntities();
            Deal        deal = se.Deals.Find(dealID);

            if (deal != null)
            {
                DealTask task = new Models.DealTask();
                task.type            = 8;
                task.TaskName        = deal.DealTasks.Where(u => u.type == 8).First().TaskName;
                task.status          = 1;
                task.Deadline        = DateTime.Now;
                task.CreateDate      = DateTime.Now;
                task.TaskDescription = mailcontent;
                task.dealID          = dealID;
                task.TaskContent     = "ReplyEmail";
                se.DealTasks.Add(task);
                se.SaveChanges();
            }
            return(RedirectToAction("Detail", new { id = dealID }));
        }
Beispiel #25
0
 public ActionResult CreateNewTask(int dealID, String title, String description, int type, String deadline)
 {
     try
     {
         SSMEntities se   = new SSMEntities();
         DealTask    task = new DealTask();
         task.dealID          = dealID;
         task.Deadline        = DateTime.Parse(deadline);
         task.CreateDate      = DateTime.Today;
         task.status          = 1;
         task.type            = type;
         task.TaskDescription = description;
         task.TaskName        = title;
         se.DealTasks.Add(task);
         se.SaveChanges();
         return(RedirectToAction("Detail", new { id = dealID }));
     }
     catch (Exception e)
     {
     }
     return(RedirectToAction("Index"));
 }
Beispiel #26
0
        public JsonResult removeEmail(int mailid)
        {
            SSMEntities se   = new SSMEntities();
            DealTask    task = se.DealTasks.Find(mailid);

            if (task != null)
            {
                try {
                    foreach (DealTask alltask in task.Deal.DealTasks.Where(u => u.type == 8 && u.Deadline > task.Deadline).ToList())
                    {
                        alltask.TaskContent = (int.Parse(alltask.TaskContent) - 1) + "";
                    }
                    se.DealTasks.Remove(task);
                    se.SaveChanges();
                    return(Json(new { sentresult = "succeed" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception e) {
                }
            }

            return(Json(new { sentresult = "fail" }, JsonRequestBehavior.AllowGet));
        }
Beispiel #27
0
 public JsonResult PrePlanSwitchStatus(int id)
 {
     try
     {
         SSMEntities se = new SSMEntities();
         PrePurchase_FollowUp_Plan myplan   = se.PrePurchase_FollowUp_Plan.Find(id);
         softwareProduct           software = myplan.softwareProduct;
         foreach (PrePurchase_FollowUp_Plan plan in software.PrePurchase_FollowUp_Plan.ToList())
         {
             if (plan.id != id)
             {
                 plan.isOperation = false;
             }
         }
         myplan.isOperation = !myplan.isOperation;
         se.SaveChanges();
         return(Json(new { result = "succeed" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception e)
     {
     }
     return(Json(new { result = "fail" }, JsonRequestBehavior.AllowGet));
 }
Beispiel #28
0
        public ActionResult savechangesSchedule(String date)
        {
            SSMEntities se     = new SSMEntities();
            String      userID = User.Identity.GetUserId();
            AspNetUser  user   = se.AspNetUsers.Find(userID);

            string[] busyDates = date.Split(new[] { "start" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (String thisdate in busyDates)
            {
                string[] startend = thisdate.Split(new[] { "end" }, StringSplitOptions.RemoveEmptyEntries);
                Calendar cal      = new Calendar();
                cal.repeat    = true;
                cal.startTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
                                .AddMilliseconds(double.Parse(startend[0]))
                                .ToLocalTime();
                cal.endTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
                              .AddMilliseconds(double.Parse(startend[1]))
                              .ToLocalTime();
                cal.userID = userID;
                se.Calendars.Add(cal);
                se.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Beispiel #29
0
        public int createAndGetDealID(Deal deal, int productID, int plann)
        {
            SSMEntities     se      = new SSMEntities();
            softwareProduct product = se.softwareProducts.Find(productID);

            if (product != null)
            {
                deal.ProductID = productID;
            }
            deal.Creator         = User.Identity.GetUserId();
            deal.StartDate       = DateTime.Today;
            deal.Stage           = 1;
            deal.Probability     = 0;
            deal.CompleteOn      = null;
            deal.LastUpdateStage = null;
            deal.Status          = 1;
            deal.CurrentPlanID   = product.PrePurchase_FollowUp_Plan.Where(u => u.isOperation).FirstOrDefault().id;

            se.Deals.Add(deal);
            se.SaveChanges();
            Deal_Item         ite = new Deal_Item();
            productMarketPlan pla = se.productMarketPlans.Find(plann);

            ite.planID   = plann;
            ite.price    = pla.ceilPrice;
            ite.Quantity = 1;
            ite.dealID   = deal.id;
            se.Deal_Item.Add(ite);
            deal.Value = ite.price;
            se.SaveChanges();
            Deal_SaleRep_Respon dealrespont = new Deal_SaleRep_Respon();

            dealrespont.dealID = deal.id;
            dealrespont.userID = deal.Creator;
            se.Deal_SaleRep_Respon.Add(dealrespont);
            se.SaveChanges();
            contact contact = se.contacts.Find(deal.Client);
            int     day     = 0;
            PrePurchase_FollowUp_Plan plan = deal.softwareProduct.PrePurchase_FollowUp_Plan.Where(u => u.isOperation == true).FirstOrDefault();

            if (contact != null)
            {
                foreach (Plan_Step tep in plan.Plan_Step)
                {
                    if (tep.TimeFromLastStep == null)
                    {
                        tep.TimeFromLastStep = 0;
                    }
                    day = day + (int)tep.TimeFromLastStep;
                    DealTask task = new DealTask();
                    task.dealID          = deal.id;
                    task.TaskDescription = tep.StepEmailContent;
                    task.status          = 1;
                    if (tep.RequireMoreDetail)
                    {
                        task.status = 7;
                    }
                    task.Deadline    = DateTime.Now.AddDays(day);
                    task.CreateDate  = DateTime.Now;
                    task.TaskContent = tep.stepNo + "";
                    task.TaskName    = tep.subject + " [#:" + deal.id + "]";
                    task.type        = 8;
                    se.DealTasks.Add(task);
                    se.SaveChanges();
                    if (task.TaskDescription.Contains(se.ConfigureSys.Find(13).value))
                    {
                        String replaceall = "";
                        foreach (Deal_Item item in task.Deal.Deal_Item)
                        {
                            TrialAccount trial = item.productMarketPlan.TrialAccounts.Where(u => u.contactID == null).FirstOrDefault();
                            replaceall = replaceall + '\n' + "User Name for " + item.productMarketPlan.Name + ": " + trial.UserName + " Password: " + trial.Password;
                            TrialAccount trialupdate = se.TrialAccounts.Find(trial.AccountID);
                            trialupdate.contactID = task.Deal.contact.id;
                            se.SaveChanges();
                        }
                        task.TaskDescription = task.TaskDescription.Replace(se.ConfigureSys.Find(13).value, replaceall);
                    }
                    se.SaveChanges();
                }
            }


            return(deal.id);
        }
Beispiel #30
0
        public ActionResult DealWon(int id)
        {
            SSMEntities    se       = new SSMEntities();
            DealRepository dealrepo = new DealRepository(se);
            Deal           deal     = dealrepo.getByID(id);

            if (deal != null)
            {
                customer cus = new customer();
                if (se.AspNetUsers.Where(us => us.UserName.Equals(deal.contact.emails)).FirstOrDefault() == null)
                {
                    cus.cusAddress = deal.contact.Street + " " + deal.contact.City + " " + deal.contact.Region + " ";
                    cus.cusCompany = 1;
                    cus.cusEmail   = deal.contact.emails;
                    cus.cusName    = deal.contact.FirstName + " " + deal.contact.MiddleName + " " + deal.contact.LastName;
                    cus.cusPhone   = deal.contact.Phone;
                    se.customers.Add(cus);
                    se.SaveChanges();
                    AccountController ac           = new AccountController();
                    String            cusAccountID = ac.RegisterNewAccount(cus.cusEmail, "320395@qwE", System.Web.HttpContext.Current, "Customer");
                    cus.userID = cusAccountID;
                    se.SaveChanges();
                }
                else
                {
                    AspNetUser thiscus = se.AspNetUsers.Where(us => us.UserName.Equals(deal.contact.emails)).First();
                    cus = thiscus.customers.First();
                }
                deal.Status = 3;

                order order = new order();
                order.customerID = cus.id;
                float price = 0;
                order.orderNumber = se.orders.ToList().Count() + 1;
                order.subtotal    = deal.Value;
                order.status      = 1;
                order.total       = (double)order.subtotal * 1.1;
                order.VAT         = (double)order.subtotal * 0.1;
                order.fromDeal    = deal.id;
                order.createDate  = DateTime.Now;
                Storage storeage = new Storage();
                se.orders.Add(order);
                se.SaveChanges();
                order.Contract = storeage.uploadfile(cus.userID, "order" + order.id);
                se.SaveChanges();
                deal.Status = 3;
                se.SaveChanges();
                bool validLicense = true;
                foreach (Deal_Item dealitem in deal.Deal_Item)
                {
                    int lcount = se.Licenses.Where(u => u.PlanID == dealitem.planID && u.status == null && u.SaleRepResponsible == null).Count();
                    if (lcount < dealitem.Quantity)
                    {
                        validLicense = false;
                    }
                }
                if (validLicense)
                {
                    foreach (Deal_Item dealitem in deal.Deal_Item)
                    {
                        for (int i = 0; i < dealitem.Quantity; i++)
                        {
                            License license = se.Licenses.Where(u => u.PlanID == dealitem.planID && u.status == null && u.SaleRepResponsible == null).FirstOrDefault();
                            if (license != null)
                            {
                                license.customerID         = cus.id;
                                license.SaleRepResponsible = deal.Deal_SaleRep_Respon.LastOrDefault().userID;
                                license.status             = 1;
                                OrderItem orderItem = new OrderItem();
                                orderItem.orderID   = order.id;
                                orderItem.planID    = dealitem.planID;
                                orderItem.SoldPrice = (double)dealitem.price;
                                orderItem.LicenseID = license.id;
                                se.OrderItems.Add(orderItem);
                            }
                            else
                            {
                                return(RedirectToAction("Detail", new { id = deal.id }));
                            }
                        }
                    }

                    se.SaveChanges();
                }
                else
                {
                    return(RedirectToAction("Detail", new { id = deal.id }));
                }
                Notification noti = new Notification();
                noti.NotiName    = "Contract successfully created";
                noti.NotiContent = "Deal No." + deal.id + ": has finished with a contract and order";
                noti.userID      = deal.Deal_SaleRep_Respon.LastOrDefault().userID;
                noti.CreateDate  = DateTime.Now;
                noti.viewed      = false;
                noti.hreflink    = "/Deal/Detail?id=" + deal.id;
                se.Notifications.Add(noti);
                se.SaveChanges();
                deal.Status = 5;
                se.SaveChanges();
                //}
                //catch (Exception e) {
                //    return Json(new { result = "sad" }, JsonRequestBehavior.AllowGet);
                //}
            }
            return(RedirectToAction("Detail", new { id = deal.id }));
        }