public ActionResult CreateCases() { if (BL.CurrentUser.Instance != null && BL.CurrentUser.Instance.VerifiedUser.UserId != Guid.Empty) { //Guid customerid = new Guid(BL.CurrentUser.Instance.VerifiedUser.CompanyName); //EntityReference CustomerId = new EntityReference("contact", customerid); lstSite = GetSiteOnCustomer(BL.CurrentUser.Instance.VerifiedUser.CompanyName); BL.TicketData Model; if (lstSite.Count > 0) { Model = new BL.TicketData() { lstSubject = GetSubject(), lstSite = GetSiteOnCustomer(BL.CurrentUser.Instance.VerifiedUser.CompanyName) }; } else { Model = new BL.TicketData() { lstSubject = GetSubject() }; } ViewBag.LiDashboard = "class="; ViewBag.LiGetAllCasesForIncident = "class="; ViewBag.LiCreateCases = "class=active"; ViewBag.LiPassword = "******"; return(View("CreateCases", Model)); } else { return(RedirectToAction("../Activity/Login")); } }
public ActionResult EditCases(Guid id) { if (BL.CurrentUser.Instance != null && BL.CurrentUser.Instance.VerifiedUser.UserId != Guid.Empty) { BL.RecordList AllCases = new BL.RecordList() { lstData = null }; lstSite = GetSiteOnCustomer(BL.CurrentUser.Instance.VerifiedUser.CompanyName); BL.TicketData Model; if (lstSite.Count > 0) { Model = new BL.TicketData() { lstSubject = GetSubject(), lstSite = GetSiteOnCustomer(BL.CurrentUser.Instance.VerifiedUser.CompanyName) }; } else { Model = new BL.TicketData() { lstSubject = GetSubject() }; } lstTroubleTicket1 = PortalRepository.GetIdWiseIncidentData("incident", Service, id); if (lstTroubleTicket1.Count > 0) { AllCases = new BL.RecordList() { lstData = lstTroubleTicket1 } } ; else { AllCases = new BL.RecordList() { lstData = null } }; Model.incidentid = id; Model.description = AllCases.lstData[0].description; EntityReference CustomerId = new EntityReference("account", AllCases.lstData[0].customerid); Model.customerid = CustomerId.Id.ToString(); EntityReference SiteName = new EntityReference("new_projectsite", AllCases.lstData[0].new_sitename); Model.new_name = SiteName.Id.ToString(); EntityReference ContactId = new EntityReference("contact", AllCases.lstData[0].primarycontactid); Model.primarycontactid = ContactId.Id.ToString(); EntityReference SubjectId = new EntityReference("subject", AllCases.lstData[0].subjectid); Model.subjectid = SubjectId.Id.ToString(); Model.title = AllCases.lstData[0].title; Model.PageMessage = ""; return(View("CreateCases", Model)); } else { return(RedirectToAction("../Activity/Login")); } }
public ActionResult SaveCases(BL.TicketData Model) { try { if (Service == null) { Service = BL.OrganizationUtility.GetCRMService(); } if (BL.CurrentUser.Instance != null && BL.CurrentUser.Instance.VerifiedUser.UserId != Guid.Empty) { BL.User us = new BL.User(); //QueryExpression query = new QueryExpression("contact"); //query.ColumnSet = new ColumnSet("contactid", "parentcustomerid"); ////query.Criteria.AddCondition(new ConditionExpression("new_account", ConditionOperator.Equal, CustId)); //EntityCollection Col = Service.RetrieveMultiple(query); // Entity entity = context.InputParameters["account"] as Entity; if (Model.incidentid == null || Model.incidentid == new Guid("00000000-0000-0000-0000-000000000000")) { Entity entity = new Entity("incident"); //entity.Id = ""; entity.LogicalName = "incident"; //entity.Attributes["incidentid"] = ; entity.Attributes["title"] = Model.title; Guid subjectid = new Guid(Model.subjectid); EntityReference SubjectId = new EntityReference("subject", subjectid); entity.Attributes["subjectid"] = SubjectId; entity.Attributes["description"] = Model.description; Guid customerid = new Guid(BL.CurrentUser.Instance.VerifiedUser.CompanyName); EntityReference CustomerId = new EntityReference("account", customerid); entity.Attributes["customerid"] = CustomerId; Guid sitename = new Guid(Model.new_name); EntityReference SiteName = new EntityReference("new_projectsite", sitename); entity.Attributes["new_sitename"] = SiteName; Guid contactid = new Guid(BL.CurrentUser.Instance.VerifiedUser.UserId.ToString()); EntityReference ContactId = new EntityReference("contact", contactid); entity.Attributes["primarycontactid"] = ContactId; //new_sitename entity.Attributes["createdby"] = ContactId; //new_sitename var incId = Service.Create(entity); #region SaveNotes Entity entity_notes = new Entity("annotation"); entity_notes["subject"] = " by " + BL.CurrentUser.Instance.VerifiedUser.UserName; entity_notes["notetext"] = "*WEB*" + Model.description; if (Model.Attachment != null) { if (Model.Attachment.ContentLength > 0) { var fname = Path.GetFileNameWithoutExtension(Model.Attachment.FileName) + (DateTime.Now).ToString("ddMMyyhhmmss"); var FExtension = Path.GetExtension(Model.Attachment.FileName); var fileName = fname + FExtension;// //var fileName = Path.GetFileName(ModelNotes.Attachment.FileName);// + (DateTime.Now).ToString("dd-MM-yyyy")); var path = Path.Combine(Server.MapPath("~/App_Data/"), fileName); Model.Attachment.SaveAs(path); FileStream stream = new FileStream(path, FileMode.Open); byte[] byteData = new byte[stream.Length]; stream.Read(byteData, 0, byteData.Length); stream.Close(); entity_notes["filename"] = fileName; entity_notes["mimetype"] = Model.Attachment.ContentType; entity_notes["documentbody"] = System.Convert.ToBase64String(byteData); } } EntityReference IncidentIdNew = new EntityReference("incident", incId); entity_notes["objectid"] = IncidentIdNew; EntityReference User = new EntityReference("contact", BL.CurrentUser.Instance.VerifiedUser.UserId); //entity["createdby"] = User.Id; Service.Create(entity_notes); #endregion Model.PageMessage = "Case Successfully Created"; } else { Entity entity = new Entity("incident"); //entity.Id = ""; entity.LogicalName = "incident"; entity.Attributes["incidentid"] = Model.incidentid; entity.Attributes["title"] = Model.title; Guid subjectid = new Guid(Model.subjectid); EntityReference SubjectId = new EntityReference("subject", subjectid); entity.Attributes["subjectid"] = SubjectId; entity.Attributes["description"] = Model.description; Guid customerid = new Guid(BL.CurrentUser.Instance.VerifiedUser.CompanyName); EntityReference CustomerId = new EntityReference("account", customerid); entity.Attributes["customerid"] = CustomerId; Guid sitename = new Guid(Model.new_name); EntityReference SiteName = new EntityReference("new_projectsite", sitename); entity.Attributes["new_sitename"] = SiteName; Guid contactid = new Guid(BL.CurrentUser.Instance.VerifiedUser.UserId.ToString()); EntityReference ContactId = new EntityReference("contact", contactid); entity.Attributes["primarycontactid"] = ContactId;//new_sitename Service.Update(entity); Model.PageMessage = "Case Successfully Updated"; } } //EditCases(Model.incidentid); return(RedirectToAction("GetAllCasesForIncident")); } catch (Exception ex) { return(RedirectToAction("../Activity/Login")); } }