Example #1
0
 public Opportunity_OpportunityContactMappingDTO(OpportunityContactMapping OpportunityContactMapping)
 {
     this.ContactId     = OpportunityContactMapping.ContactId;
     this.OpportunityId = OpportunityContactMapping.OpportunityId;
     this.Contact       = OpportunityContactMapping.Contact == null ? null : new Opportunity_ContactDTO(OpportunityContactMapping.Contact);
     this.Errors        = OpportunityContactMapping.Errors;
 }
        public IHttpActionResult AddOpportunity()
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var form = HttpContext.Current.Request.Form;
                    var opportunityCategories = JsonConvert.DeserializeObject <List <keyValueModel> >(form.Get("Categories"));

                    Opportunity opp = new Opportunity();
                    opp.Client_Id   = form.Get("client");
                    opp.CreatedDate = MasterDataController.GetIndianTime(DateTime.UtcNow);
                    opp.CreatedBy   = User.Identity.GetUserId();

                    if (form.Get("assignTo") != null)
                    {
                        opp.TaskOwner  = form.Get("assignTo");
                        opp.AssignedTo = form.Get("assignTo");
                    }
                    else
                    {
                        opp.TaskOwner  = User.Identity.GetUserId();
                        opp.AssignedTo = User.Identity.GetUserId();
                    }

                    opp.OpportunityName = form.Get("opportunity");
                    opp.RefferedBy      = form.Get("refferedBy");
                    opp.Org_Id          = Convert.ToInt32(form.Get("orgId"));
                    opp.Status          = form.Get("Status");

                    opp.Description = form.Get("comments");
                    opp.Location_Id = Convert.ToInt32(form.Get("Location"));

                    if (opp.Status == "Accepted")
                    {
                        opp.EDOC = DateTime.Parse(form.Get("edoc"));
                        opp.EDOS = DateTime.Parse(form.Get("edos"));
                    }
                    else if (opp.Status == "Completed")
                    {
                        opp.ActualCompletedDate = Convert.ToDateTime(form.Get("CompletedDate"));
                    }
                    db.Opportunities.Add(opp);

                    for (int i = 0; i < opportunityCategories.Count; i++)
                    {
                        OpportunityCategoryMapping oppCat = new OpportunityCategoryMapping();
                        oppCat.Category_Id = Convert.ToInt32(opportunityCategories[i].value);

                        opp.OpportunityCategoryMappings.Add(oppCat);
                    }

                    if (form.Get("contactPersons") != null)
                    {
                        var checkedContacts = JsonConvert.DeserializeObject <List <string> >(form.Get("contactPersons"));
                        for (int j = 0; j < checkedContacts.Count; j++)
                        {
                            OpportunityContactMapping oppContact = new OpportunityContactMapping();
                            oppContact.Contact_Id = Convert.ToInt32(checkedContacts[j]);

                            opp.OpportunityContactMappings.Add(oppContact);
                        }
                    }

                    OpportunitiesLog oppLog = new OpportunitiesLog();

                    oppLog.CreatedBy   = User.Identity.GetUserId();
                    oppLog.CreatedDate = MasterDataController.GetIndianTime(DateTime.UtcNow);
                    oppLog.AssignedTo  = opp.TaskOwner;
                    oppLog.Status      = form.Get("Status");
                    oppLog.Comments    = form.Get("comments");

                    opp.OpportunitiesLogs.Add(oppLog);

                    var files           = HttpContext.Current.Request.Files;
                    var fileAttachments = new List <HttpPostedFile>();

                    for (int i = 0; i < files.Count; i++)
                    {
                        fileAttachments.Add(files[i]);
                    }
                    foreach (var file in fileAttachments)
                    {
                        var fileDirecory = HttpContext.Current.Server.MapPath("~/CommentAttachments");

                        if (!Directory.Exists(fileDirecory))
                        {
                            Directory.CreateDirectory(fileDirecory);
                        }

                        var fileName = file.FileName;
                        var filePath = Path.Combine(fileDirecory, fileName);
                        file.SaveAs(filePath);

                        OpportunityAttachment attachment = new OpportunityAttachment();

                        attachment.FileName       = Path.GetFileNameWithoutExtension(file.FileName);
                        attachment.FileAttachment = Path.Combine(ConfigurationManager.AppSettings["ApiUrl"], "CommentAttachments", fileName);
                        oppLog.OpportunityAttachments.Add(attachment);
                    }
                    db.Opportunities.Add(opp);
                    db.SaveChanges();
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
                return(Content(HttpStatusCode.InternalServerError, "An error occured , please try again later"));
            }
        }
Example #3
0
 public OpportunityReport_ContactMappingDTO(OpportunityContactMapping OpportunityContactMapping)
 {
     this.OpportunityId = OpportunityContactMapping.OpportunityId;
     this.ContactId     = OpportunityContactMapping.ContactId;
     this.Contact       = OpportunityContactMapping.Contact == null ? null : new OpportunityReport_ContactDTO(OpportunityContactMapping.Contact);
 }