Example #1
0
        /// <summary>
        /// AddLead
        /// </summary>
        /// <param name="lead"></param>
        /// <returns></returns>
        public long AddLead(Lead lead)
        {
            using (var context = new fyxmeContext())
            {
                context.Leads.Add(lead);
                context.SaveChanges();

                return lead.Cases.ElementAt(0).CaseNo;
            }
        }
Example #2
0
        public ActionResult AddRequest(RequestViewModel request)
        {
            if (ModelState.IsValid)
            {
                // Save files on server.
                string uploadDirImages = Server.MapPath(WebConfigurationManager.AppSettings["uploadPicsDirectory"].ToString());
                List<string> uploadedNewNameImages = new List<string>();

                for (int iImages = 1; iImages <= 4; iImages++)
                {
                    HttpPostedFileBase uploadedFile = Request.Files["txtUFile" + iImages];
                    if (uploadedFile != null && uploadedFile.ContentLength > 0 && Request["txtUploadPic" + iImages].Length > 0)
                    {
                        int pos = uploadedFile.FileName.LastIndexOf(".");
                        string fileExtension = uploadedFile.FileName.Substring(pos + 1);
                        string fileNewImageName = String.Concat(Guid.NewGuid().ToString(), ".", fileExtension);

                        uploadedFile.SaveAs(String.Concat(uploadDirImages, fileNewImageName));
                        uploadedNewNameImages.Add(fileNewImageName);
                    }
                }

                // Get selected CarMMY id
                int carMMYId = 0;
                if (!String.IsNullOrEmpty(request.SelectedCarModelId) && !String.IsNullOrEmpty(request.SelectedCarYearId)) {
                    carMMYId = cmRepo.GetCarMMYId(request.SelectedCarModelId, Convert.ToInt32(request.SelectedCarYearId));
                }

                // Add lead object
                // Lead
                Lead l = new Lead();
                l.FirstName = request.FirstName;
                l.LastName = request.LastName;
                l.Email = request.Email;
                l.PhoneNumber = request.PhoneNumber;
                l.ZipCode = request.ZipCode;
                l.StatusId = (int)EStatus.Received;     // Default status
                l.Origin = "Fyxme Website";             // Default origin
                l.CreatedBy = 999;                      // Added by customer
                
                // Case
                Case c = new Case();
                if (carMMYId > 0) {
                    c.CarMMYId = (int)carMMYId;
                }
                c.CaseDesc = request.DamageDescription;
                c.StatusId = (int)EStatus.Received;
                c.SalesRepId = 0;
                c.CreatedBy = 999;                      // Added by customer

                // Case pictures
                int picRank = 1;
                List<CasePicture> cp = new List<CasePicture>();

                foreach (string uploadedImage in uploadedNewNameImages)
                {
                    CasePicture casePic = new CasePicture()
                    {
                        PictureRank = (byte)picRank,
                        PictureName = uploadedImage,
                        PictureLocation = uploadDirImages,
                        CreatedBy = 999,
                    };

                    cp.Add(casePic);
                    picRank++;
                }

                c.CasePictures = cp;
                l.Cases.Add(c);

                // Save lead object and get CaseId
                long caseId = cmRepo.AddLead(l);

                // Send emails
                SendEmailToClient(request, caseId);
                SendEmailToAdmin(request, caseId, uploadedNewNameImages);

                // Redirect to confirmation view.
                return RedirectToAction("Index", "Home", new { showConfirmBox = "Customer" });
            }

            return RedirectToAction("Index");
        }