public IHttpActionResult AddClientTicketResponse()
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var form = HttpContext.Current.Request.Form;

                    ActivitiesLog actLog = new ActivitiesLog();
                    actLog.AssignedBy  = User.Identity.GetUserId();
                    actLog.AssignedTo  = form.Get("assignedTo");
                    actLog.Status      = "Pending";
                    actLog.Description = form.Get("description");
                    actLog.TaskDate    = MasterDataController.GetIndianTime(DateTime.Now);
                    actLog.TaskId      = form.Get("taskId");

                    db.ActivitiesLogs.Add(actLog);
                    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"));
            }
        }
Пример #2
0
        public IHttpActionResult UpdateItemModel(int id)
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var form = HttpContext.Current.Request.Form;

                    ItemsMaster im = db.ItemsMasters.Find(id);
                    im.Brand        = form.Get("Brand");
                    im.ModelNumber  = form.Get("ModelNumber");
                    im.ItemName     = form.Get("ItemName");
                    im.HSNCode      = form.Get("HsnCode");
                    im.UPC          = form.Get("Upc");
                    im.EAN          = form.Get("Ean");
                    im.Description  = form.Get("Description");
                    im.ItemContents = form.Get("Contents");
                    im.MadeIn       = Convert.ToInt32(form.Get("Country"));
                    im.Manufacturer = form.Get("Manufacturer");
                    // im.PowerInput = Convert.ToInt32(form.Get("PowerInput"));
                    int?powerUnit = im.PowerInput;
                    if (form.Get("PowerInput") != "")
                    {
                        im.PowerInput      = Convert.ToInt32(form.Get("PowerInput"));
                        im.PowerInputUnits = form.Get("PowerUnits");
                    }
                    else
                    {
                        im.PowerInput      = null;
                        im.PowerInputUnits = null;
                    }

                    im.ThresholdQuantity = Convert.ToInt32(form.Get("ThresholdValue"));
                    im.UpdatedBy         = User.Identity.GetUserId();
                    im.LastUpdated       = MasterDataController.GetIndianTime(DateTime.Now);
                    im.Units             = form.Get("Units");
                    im.GST             = Convert.ToDecimal(form.Get("Gst")) / 2;
                    im.CGST            = Convert.ToDecimal(form.Get("Gst")) / 2;
                    im.SrlNoExists     = Convert.ToBoolean(form.Get("SrlNoExits"));
                    db.Entry(im).State = EntityState.Modified;
                    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"));
            }
        }
Пример #3
0
        public IHttpActionResult LogLocationData(object myObject)
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var root     = JObject.Parse(myObject.ToString()).First.First;
                    var location = JsonConvert.DeserializeObject <LocationInfo>(root.ToString());
                    if (db.EmployeeAttendanceLogs.Any(x => x.Emp_Id == location.EmployeeId && location.Time == x.Time))
                    {
                        return(Ok());
                    }
                    string Address = null;
                    try
                    {
                        string      latlon = location.Latitude + "," + location.Longitude;
                        XmlDocument xDoc   = new XmlDocument();
                        xDoc.Load("https://maps.googleapis.com/maps/api/geocode/xml?latlng=" + latlon + "&key=AIzaSyCPbyemMRyuWmR7yiD-nIwXaaeZaw-jK9o");
                        XmlNodeList xNodelst = xDoc.GetElementsByTagName("result");
                        XmlNode     xNode    = xNodelst.Item(0);
                        Address = xNode.SelectSingleNode("formatted_address").InnerText;
                    }
                    catch
                    {
                    }

                    EmployeeAttendanceLog eal = new EmployeeAttendanceLog()
                    {
                        Emp_Id       = location.EmployeeId,
                        Latitude     = location.Latitude,
                        Longitude    = location.Longitude,
                        IsClockIn    = location.IsClockIn,
                        IsClockOut   = location.IsClockOut,
                        Time         = MasterDataController.GetIndianTime(location.Time),
                        Address      = Address,
                        InsertedTime = MasterDataController.GetIndianTime(DateTime.UtcNow)
                    };
                    db.EmployeeAttendanceLogs.Add(eal);
                    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"));
            }
        }
Пример #4
0
        public IHttpActionResult AddMaterialRequest()
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var form        = HttpContext.Current.Request.Form;
                    var items       = JsonConvert.DeserializeObject <List <BilledItemsModel> >(form.Get("items"));
                    var emp         = db.Employees.Where(x => x.Role_Id == "8").FirstOrDefault();
                    var category    = db.Categories.Where(x => x.Name == "Stock").FirstOrDefault().Id;
                    var subCategory = db.SubCategories.Where(x => x.Name == "Stock").FirstOrDefault().Id;


                    StockRequest stockReq = new StockRequest();

                    stockReq.Employee          = User.Identity.GetUserId();
                    stockReq.Client            = form.Get("Client");
                    stockReq.ExpectedStockDate = Convert.ToDateTime(form.Get("expectedDate"));
                    stockReq.Project           = Convert.ToInt32(form.Get("project"));
                    stockReq.Status            = "Under Review";
                    stockReq.Notes             = form.Get("notes");
                    stockReq.RequestDate       = DateTime.Now;
                    stockReq.LastUpdated       = DateTime.Now;
                    stockReq.UpdatedBy         = User.Identity.GetUserId();

                    for (int i = 0; i < items.Count(); i++)
                    {
                        StockRequestMapping srm = new StockRequestMapping();
                        srm.ItemId    = items[i].ModelId;
                        srm.Quanitity = items[i].Quantity;

                        stockReq.StockRequestMappings.Add(srm);
                    }

                    Activity act = new Activity();


                    if (emp != null)
                    {
                        act.AssignedTo = emp.AspNetUserId;
                    }

                    act.CreatedBy      = User.Identity.GetUserId();
                    act.Status         = "Open";
                    act.Subject        = "Material request for project";
                    act.Project_Id     = Convert.ToInt32(form.Get("project"));
                    act.EDOC           = Convert.ToDateTime(form.Get("expectedDate"));
                    act.Client_Id      = form.Get("Client");
                    act.Priority       = 0;
                    act.CreatedDate    = DateTime.Now;
                    act.TaskType       = "Client";
                    act.TaskOwner      = act.AssignedTo;
                    act.Description    = form.Get("notes");
                    act.TaskId         = RandomString(4);
                    stockReq.TaskId    = act.TaskId;
                    act.Category_Id    = Convert.ToInt32(category);
                    act.SubCategory_Id = Convert.ToInt32(subCategory);

                    ActivitiesLog activityLog = new ActivitiesLog();
                    activityLog.Status      = act.Status;
                    activityLog.Description = act.Description;
                    activityLog.TaskDate    = MasterDataController.GetIndianTime(DateTime.UtcNow);
                    activityLog.AssignedBy  = act.CreatedBy;
                    activityLog.AssignedTo  = act.TaskOwner;

                    act.ActivitiesLogs.Add(activityLog);

                    db.Activities.Add(act);

                    db.StockRequests.Add(stockReq);
                    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"));
            }
        }
        public IHttpActionResult FeedBackFromClient()
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var form = HttpContext.Current.Request.Form;

                    var    ticketId = form.Get("TicketId");
                    string status   = form.Get("Status");

                    Activity      activity = db.Activities.Where(x => x.TaskId == ticketId).FirstOrDefault();
                    ActivitiesLog actLog   = new ActivitiesLog();
                    if (activity != null)
                    {
                        if (status == "true")
                        {
                            activity.Status        = "Closed";
                            activity.CompletedDate = MasterDataController.GetIndianTime(DateTime.Now);

                            actLog.TaskDate    = MasterDataController.GetIndianTime(DateTime.Now);
                            actLog.TaskId      = ticketId;
                            actLog.AssignedBy  = activity.TaskOwner;
                            actLog.AssignedTo  = activity.CreatedBy;
                            actLog.Status      = "Closed by assignee";
                            actLog.Description = "Satisfactory";

                            db.ActivitiesLogs.Add(actLog);
                            db.Entry(activity).State = System.Data.Entity.EntityState.Modified;

                            var taskCreator = db.Employees.Where(x => x.AspNetUserId == activity.CreatedBy && x.Active == true).FirstOrDefault();

                            db.SaveChanges();
                        }

                        else
                        {
                            if (activity.Status == "Resolved")
                            {
                                activity.Status        = "Reopened";
                                activity.CompletedDate = null;

                                var lastWorked = db.ActivitiesLogs.Where(x => x.TaskId == ticketId).OrderByDescending(x => x.TaskDate).FirstOrDefault();

                                activity.Status        = "Reopened";
                                activity.TaskOwner     = lastWorked.AssignedBy;
                                activity.CompletedDate = null;

                                actLog.TaskDate    = MasterDataController.GetIndianTime(DateTime.Now);
                                actLog.TaskId      = ticketId;
                                actLog.AssignedTo  = lastWorked.AssignedBy;
                                actLog.AssignedBy  = User.Identity.GetUserId();
                                actLog.Status      = "Reopened";
                                actLog.Description = "Ticket Reopened ";

                                db.ActivitiesLogs.Add(actLog);
                                db.Entry(activity).State = System.Data.Entity.EntityState.Modified;

                                var taskCreator = db.Employees.Where(x => x.AspNetUserId == activity.CreatedBy && x.Active == true).FirstOrDefault();

                                if (taskCreator != null)
                                {
                                }
                                else
                                {
                                    var Client = db.Clients.Where(x => x.AspNetUserId == activity.CreatedBy).FirstOrDefault();
                                    if (Client != null)
                                    {
                                        string subject = "Your Ticket Id #" + activity.TaskId + " ( " + activity.Subject + " ) is reopened. ";
                                        string from    = "";
                                        string to      = Client.Email;
                                        var    body    = @"<div style=""border: 1px solid gray;margin-top:2px; margin-right: 2px;padding: 9px;"" > 
                                     <p> Dear " + Client.Name + ", </p>" +
                                                         "<p> your ticket with Id " + activity.TaskId + " ( " + activity.Subject + " ) is reopened and the support team will contact you soon.  " + "</p>" +
                                                         "<p> We encourage you to kindly use our support portal http://ourclientSupport.azurewebsites.net for reporting issues/Service Requests with support team or to seek any further updates on your ticket. </p>" +
                                                         "<p> CUSTOMER SERVICE: 9 66 67 24 635 </p>" +
                                                         " </div>";
                                        bool sendEmail = new EmailController().SendEmail(from, "Task Management System", to, subject, body);
                                    }
                                }

                                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"));
            }
        }
        public IHttpActionResult AddClientRequest()
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var form         = HttpContext.Current.Request.Form;
                    var clientId     = form.Get("clientId");
                    var departmentId = form.Get("departmentId");
                    int orgId        = Convert.ToInt32(form.Get("OrgId"));
                    var categoryId   = form.Get("categoryId");
                    var u            = User.Identity.GetUserId();

                    Activity activity = new Activity();

                    var user      = db.Clients.Where(x => x.AspNetUserId == u && x.Active == true).FirstOrDefault();
                    var createdby = user.Id;

                    var clientOrg = user.OrgId;

                    var emp = db.Employees.Where(x => x.Role_Id == "8").FirstOrDefault();
                    if (emp != null)
                    {
                        activity.AssignedTo = emp.AspNetUserId;
                        activity.TaskOwner  = emp.AspNetUserId;
                    }

                    activity.CreatedBy  = User.Identity.GetUserId();
                    activity.TaskType   = "Client";
                    activity.Client_Id  = user.AspNetUserId;
                    activity.Project_Id = Convert.ToInt32(form.Get("projectId"));
                    activity.EDOC       = DateTime.Now.AddDays(2);

                    activity.TaskId = RandomString(4, orgId, createdby, true);
                    db.Activities.Add(activity);

                    ActivitiesLog activityLog = new ActivitiesLog();

                    activityLog.Status      = activity.Status;
                    activityLog.Description = activity.Description;
                    activityLog.TaskDate    = MasterDataController.GetIndianTime(DateTime.UtcNow);
                    activityLog.AssignedBy  = activity.CreatedBy;
                    activityLog.AssignedTo  = activity.TaskOwner;

                    activity.ActivitiesLogs.Add(activityLog);

                    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("~/Task");

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

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

                        ActivityAttachment actAttachments = new ActivityAttachment();

                        actAttachments.AttachmentURL = Path.Combine(ConfigurationManager.AppSettings["ApiUrl"], "Task", fileName);
                        actAttachments.Name          = Path.GetFileNameWithoutExtension(file.FileName);
                        activityLog.ActivityAttachments.Add(actAttachments);
                    }


                    var    from   = "";
                    var    to     = "";
                    string name   = "";
                    var    taskId = activity.TaskId;

                    var client = db.Clients.Where(x => x.AspNetUserId == activity.CreatedBy && x.Active == true).FirstOrDefault();
                    to   = client.Email;
                    name = client.Name;


                    var empl = db.Employees.Where(x => x.AspNetUserId == activity.AssignedTo && x.Active == true).FirstOrDefault();
                    to   = empl.Email;
                    name = empl.FirstName + " " + empl.LastName;

                    string subject = "You have created a new ticket with ticket Id #" + taskId;

                    var body = @"<div style=""border: 1px solid gray;margin-top:2px; margin-right: 2px;padding: 9px;"" > 
                                     <p> Dear " + name + ", </p>" +
                               "<p> Greetings! Thank you for contacting our support team. We received your request in our system and we have started working on priority.</p>" +
                               "<p> We will approach you soon if we require any further details to probe and expedite on the issue. Please allow us some time to give you an update on the progress on resolution.Your patience till then is much appreciated.</p> " +
                               "<p> We encourage you to kindly use our support portal http://ourclientSupport.azurewebsites.net for reporting issues/Service Requests with support team or to seek any further updates on your ticket. </p>" +
                               "<p> If you are experiencing any delays or for any further assistance you are feel free to contact on below numbers:</p>" +
                               "<p> CUSTOMER SERVICE: 9 66 67 24 365 </p>" +
                               " </div>";
                    bool sendmail = new EmailController().SendEmail(from, "Task Management System", to, subject, body);

                    db.SaveChanges();
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                return(Content(System.Net.HttpStatusCode.InternalServerError, "An error occured please try again later"));
            }
        }
        public IHttpActionResult AddOrganisation()
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var form = HttpContext.Current.Request.Form;
                    var OrganisationLocations = JsonConvert.DeserializeObject <List <ViewModels.OrganisationLocation> >(form.Get("OrgLocations"));

                    Organisation org = new Organisation();
                    org.OrgName        = form.Get("orgName");
                    org.WebSite        = form.Get("website");
                    org.Email          = form.Get("Email");
                    org.PrimaryPhone   = form.Get("primaryPhoneNum");
                    org.SecondaryPhone = form.Get("secondaryPhoneNum");
                    org.EmpPrefix      = form.Get("empPrefix").ToUpper();
                    org.PAN            = form.Get("pan");
                    org.GST            = form.Get("gst");
                    org.TIN            = form.Get("tin");
                    org.UpdatedBy      = User.Identity.GetUserId();
                    org.LastUpdated    = MasterDataController.GetIndianTime(DateTime.Now);

                    var EmpPrefixExists = db.Organisations.Where(x => x.EmpPrefix == org.EmpPrefix).FirstOrDefault();

                    if (EmpPrefixExists != null)
                    {
                        return(Content(HttpStatusCode.InternalServerError, "Organisation with the same employee prefix already exists "));
                    }

                    var file = HttpContext.Current.Request.Files;

                    if (file.Count > 0)
                    {
                        var image         = file["OrgLogo"];
                        var fileExtension = Path.GetExtension(image.FileName);

                        var fileDirecory = HttpContext.Current.Server.MapPath("~/OrgLogos");
                        if (!Directory.Exists(fileDirecory))
                        {
                            Directory.CreateDirectory(fileDirecory);
                        }
                        var fileName = DateTime.Now.Ticks + "_" + image.FileName;
                        var filepath = Path.Combine(fileDirecory, fileName);
                        image.SaveAs(filepath);
                        org.Logo = Path.Combine(ConfigurationManager.AppSettings["ApiUrl"], "OrgLogos", fileName);
                    }

                    for (int i = 0; i < OrganisationLocations.Count(); i++)
                    {
                        OrgansationLocation orgLoc = new OrgansationLocation();

                        orgLoc.AddressLine1 = OrganisationLocations[i].AddressLine1;
                        orgLoc.AddressLine2 = OrganisationLocations[i].AddressLine2;
                        orgLoc.CountryId    = Convert.ToInt32(OrganisationLocations[i].Country);
                        orgLoc.StateId      = OrganisationLocations[i].State;
                        orgLoc.CityId       = OrganisationLocations[i].City;
                        orgLoc.ZIP          = OrganisationLocations[i].ZIP;

                        org.OrgansationLocations.Add(orgLoc);
                    }

                    db.Organisations.Add(org);
                    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"));
            }
        }
        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"));
            }
        }
        public IHttpActionResult EditOpportunity(int oppId)
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var         form         = HttpContext.Current.Request.Form;
                    var         assingedTo   = form.Get("assignee");
                    var         status       = form.Get("status");
                    var         followupDate = form.Get("followupon");
                    Opportunity opportunity  = db.Opportunities.Where(x => x.Id == oppId).FirstOrDefault();

                    var userId = User.Identity.GetUserId();
                    //  int UserId = db.Employees.Where(x => x.AspNetUserId == userId).FirstOrDefault().Id;
                    opportunity.Status        = status;
                    opportunity.LastUpdated   = MasterDataController.GetIndianTime(DateTime.Now);
                    opportunity.LastUpdatedBy = User.Identity.GetUserId();
                    if (followupDate != "")
                    {
                        opportunity.FollowUpOn = Convert.ToDateTime(form.Get("followupon"));
                    }
                    OpportunitiesLog oppLog = new OpportunitiesLog();

                    if (assingedTo != null)
                    {
                        oppLog.AssignedTo     = (assingedTo);
                        opportunity.TaskOwner = (assingedTo);
                    }
                    else
                    {
                        oppLog.AssignedTo = opportunity.TaskOwner;
                    }

                    oppLog.CreatedDate   = MasterDataController.GetIndianTime(DateTime.UtcNow);
                    oppLog.OpportunityId = oppId;
                    oppLog.Status        = form.Get("status");
                    oppLog.CreatedBy     = User.Identity.GetUserId();
                    oppLog.Comments      = form.Get("Comments");

                    if (oppLog.Status == "Accepted")
                    {
                        opportunity.EDOC = DateTime.Parse(form.Get("edoc"));
                        opportunity.EDOS = DateTime.Parse(form.Get("edos"));
                    }
                    else if (oppLog.Status == "Completed")
                    {
                        opportunity.ActualCompletedDate = Convert.ToDateTime(form.Get("completedDate"));
                    }

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

                    if (files.Count > 0)
                    {
                        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);
                        }
                    }

                    // opportunity.OpportunitiesLogs.Add(oppLog);
                    db.OpportunitiesLogs.Add(oppLog);
                    db.Entry(opportunity).State = System.Data.Entity.EntityState.Modified;

                    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"));
            }
        }
        public IHttpActionResult EditCategory()
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var form          = HttpContext.Current.Request.Form;
                    int catId         = Convert.ToInt32(form.Get("catId"));
                    var subCategories = JsonConvert.DeserializeObject <List <NewSubCategory> >(form.Get("subCategories")).ToList();
                    var category      = db.Categories.Find(catId);

                    foreach (var subCategory in subCategories)
                    {
                        SubCategory subCat    = new SubCategory();
                        PointsLog   pointsLog = new PointsLog();

                        if (subCategory.SubCategoryId != null)
                        {
                            var subcat = db.SubCategories.Find(subCategory.SubCategoryId);
                            if (subcat.Points != subCategory.Points)
                            {
                                subcat.Points = subCategory.Points;
                                var subcatPointsLog = db.PointsLogs.Find(subCategory.PointsLogId);

                                if (subcatPointsLog != null)
                                {
                                    subcatPointsLog.ToDate          = MasterDataController.GetIndianTime(DateTime.Now);
                                    db.Entry(subcatPointsLog).State = System.Data.Entity.EntityState.Modified;
                                }
                                pointsLog.FromDate = MasterDataController.GetIndianTime(DateTime.Now);
                                pointsLog.Points   = subCategory.Points;
                                subcat.PointsLogs.Add(pointsLog);
                                db.Entry(subcat).State = System.Data.Entity.EntityState.Modified;
                            }
                            else
                            {
                                subcat.Name            = subCategory.Name;
                                subcat.Points          = subCategory.Points;
                                db.Entry(subcat).State = System.Data.Entity.EntityState.Modified;
                            }
                        }
                        else
                        {
                            subCat.Name   = subCategory.Name;
                            subCat.Points = subCategory.Points;

                            pointsLog.Points   = subCategory.Points;
                            pointsLog.FromDate = MasterDataController.GetIndianTime(DateTime.Now);

                            category.SubCategories.Add(subCat);
                            subCat.PointsLogs.Add(pointsLog);
                        }
                    }
                    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"));
            }
        }
Пример #11
0
        public IHttpActionResult EditActivity()
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var form           = HttpContext.Current.Request.Form;
                    var taskId         = form.Get("taskId");
                    var userId         = User.Identity.GetUserId();
                    var hoursWorked    = form.Get("hoursWorked");
                    var quantityWorked = form.Get("quantityWorked");
                    int orgId          = Convert.ToInt32(form.Get("OrgId"));
                    var actionType     = form.Get("actionType");

                    var activityNotification = db.AddActivityNotifications(taskId, User.Identity.GetUserId());

                    Activity mainTask = db.Activities.Find(taskId);

                    if (actionType == "Assign")
                    {
                        var assigneeList = JsonConvert.DeserializeObject <List <Assignee> >(form.Get("assigneeList"));

                        if (assigneeList.Count() > 1)
                        {
                            foreach (var assignee in assigneeList)
                            {
                                var  parentTaskLog     = JsonConvert.DeserializeObject <List <ActivityLog> >(form.Get("ParentTaskDetails"));
                                bool CreateNewActivity = AddChildTask(mainTask, assignee, parentTaskLog);
                                if (!CreateNewActivity)
                                {
                                    return(Content(HttpStatusCode.InternalServerError, "Faied to assignee task"));
                                }
                            }
                        }
                        else
                        {
                            if (mainTask.ParentTask_Id != null)
                            {
                                ActivitiesLog parentLog = new ActivitiesLog();

                                parentLog.TaskId     = mainTask.ParentTask_Id;
                                parentLog.TaskDate   = MasterDataController.GetIndianTime(DateTime.Now);
                                parentLog.AssignedBy = User.Identity.GetUserId();
                                parentLog.AssignedTo = assigneeList[0].AssigneeId;
                                parentLog.Status     = "Open";
                                if (hoursWorked != "" && hoursWorked != "NaN")
                                {
                                    parentLog.HoursWorked = Convert.ToInt32(form.Get("hoursWorked"));
                                }
                                parentLog.Description = form.Get("description");
                                if (quantityWorked != "" && quantityWorked != "NaN")
                                {
                                    parentLog.QuantityWorked = Convert.ToInt32(form.Get("quantityWorked"));
                                }

                                db.ActivitiesLogs.Add(parentLog);
                            }

                            mainTask.Status        = "Open";
                            mainTask.TaskOwner     = assigneeList[0].AssigneeId;
                            mainTask.LastUpdatedBy = User.Identity.GetUserId();
                            mainTask.LastUpdated   = MasterDataController.GetIndianTime(DateTime.Now);
                        }
                    }

                    else
                    {
                        var      childTasks = db.Activities.Where(x => x.ParentTask_Id == mainTask.TaskId).ToList();
                        Activity parentTask = db.Activities.Where(x => x.TaskId == mainTask.ParentTask_Id).FirstOrDefault();

                        ActivitiesLog activityLog = new ActivitiesLog();

                        if (childTasks.Count > 0)
                        {
                            foreach (var child in childTasks)
                            {
                                ActivitiesLog childLog = new ActivitiesLog();

                                childLog.TaskId        = child.TaskId;
                                childLog.AssignedBy    = User.Identity.GetUserId();
                                childLog.TaskDate      = MasterDataController.GetIndianTime(DateTime.Now);
                                childLog.Description   = form.Get("description");
                                childLog.BudgetedHours = Convert.ToInt32(form.Get("budgetedHours"));

                                db.ActivitiesLogs.Add(childLog);
                            }
                        }

                        if (actionType == "InProcess")
                        {
                            activityLog.AssignedTo = User.Identity.GetUserId();
                            activityLog.StartDate  = MasterDataController.GetIndianTime(Convert.ToDateTime(form.Get("edos")));
                            activityLog.EndDate    = MasterDataController.GetIndianTime(Convert.ToDateTime(form.Get("edoc")));
                            activityLog.Status     = "InProcess";

                            mainTask.Status = "InProcess";
                        }
                        else if (actionType == "Pending")
                        {
                            activityLog.AssignedTo = User.Identity.GetUserId();
                            activityLog.StartDate  = MasterDataController.GetIndianTime(Convert.ToDateTime(form.Get("edos")));
                            activityLog.EndDate    = MasterDataController.GetIndianTime(Convert.ToDateTime(form.Get("edoc")));
                            activityLog.Status     = "Pending";

                            mainTask.Status = "Pending";
                        }
                        else if (actionType == "Resolved")
                        {
                            activityLog.AssignedTo = mainTask.CreatedBy;
                            activityLog.AssignedBy = User.Identity.GetUserId();
                            activityLog.Status     = "Resolved";

                            mainTask.TaskOwner = mainTask.CreatedBy;
                            mainTask.Status    = "Resolved";
                        }
                        else if (actionType == "AcceptToClose")
                        {
                            activityLog.Status     = "Closed by assignee";
                            activityLog.AssignedBy = mainTask.TaskOwner;
                            activityLog.AssignedTo = mainTask.CreatedBy;

                            mainTask.TaskOwner = mainTask.CreatedBy;
                            mainTask.Status    = "Closed";
                        }
                        else if (actionType == "Comments")
                        {
                            activityLog.AssignedTo = mainTask.TaskOwner;
                            activityLog.AssignedBy = User.Identity.GetUserId();

                            mainTask.Status = mainTask.Status;
                        }
                        else
                        {
                            if (actionType == "Reopen")
                            {
                                activityLog.AssignedTo = mainTask.LastUpdatedBy;
                                activityLog.AssignedBy = User.Identity.GetUserId();
                                activityLog.Status     = "Reopened";

                                mainTask.Status = "Reopened";
                            }
                        }

                        if (parentTask != null)
                        {
                            ActivitiesLog parentLog = new ActivitiesLog();

                            parentLog.TaskId     = parentTask.ParentTask_Id;
                            parentLog.TaskDate   = MasterDataController.GetIndianTime(DateTime.Now);
                            parentLog.AssignedBy = User.Identity.GetUserId();
                            parentLog.AssignedTo = parentTask.TaskOwner;

                            if (actionType == "Pending" || actionType == "Comments")
                            {
                                parentLog.Status = "Pending";
                            }
                            else if (actionType == "InProcess")
                            {
                                parentLog.Status = "InProcess";
                            }
                            else if (actionType == "Assign")
                            {
                                parentLog.Status = "Open";
                            }
                            else if (actionType == "Reopen")
                            {
                                parentLog.Status = "Reopened";
                            }
                            else if (actionType == "AcceptToClose")
                            {
                                var childTasksList = db.Activities.Where(x => x.ParentTask_Id == mainTask.TaskId).ToList();
                            }
                            else if (actionType == "Resolved")
                            {
                            }
                            else
                            {
                                parentLog.Status = "";
                            }

                            parentLog.BudgetedHours = Convert.ToInt32(form.Get("budgetedHours"));
                            if (hoursWorked != "" && hoursWorked != "NaN")
                            {
                                parentLog.HoursWorked = Convert.ToInt32(form.Get("hoursWorked"));
                            }
                            parentLog.Description = form.Get("description");
                            if (quantityWorked != "" && quantityWorked != "NaN")
                            {
                                parentLog.QuantityWorked = Convert.ToInt32(form.Get("quantityWorked"));
                            }
                            db.ActivitiesLogs.Add(parentLog);
                        }

                        activityLog.AssignedBy    = User.Identity.GetUserId();
                        activityLog.TaskDate      = MasterDataController.GetIndianTime(DateTime.Now);
                        activityLog.Description   = form.Get("description");
                        activityLog.BudgetedHours = Convert.ToInt32(form.Get("budgetedHours"));
                        if (hoursWorked != "" && hoursWorked != "NaN")
                        {
                            activityLog.HoursWorked = Convert.ToInt32(form.Get("hoursWorked"));
                        }

                        if (quantityWorked != "" && quantityWorked != "NaN")
                        {
                            activityLog.QuantityWorked = Convert.ToInt32(form.Get("quantityWorked"));
                        }
                        mainTask.ActivitiesLogs.Add(activityLog);

                        mainTask.LastUpdatedBy = User.Identity.GetUserId();
                        mainTask.LastUpdated   = MasterDataController.GetIndianTime(DateTime.Now);

                        db.Entry(mainTask).State = System.Data.Entity.EntityState.Modified;
                    }
                }

                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"));
            }
        }
Пример #12
0
        public bool AddChildTask(Activity activity, Assignee assignee, List <ActivityLog> parentLog)
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var u    = User.Identity.GetUserId();
                    var user = db.Employees.Where(x => x.AspNetUserId == u).FirstOrDefault();

                    Activity      task        = new Activity();
                    ActivitiesLog activityLog = new ActivitiesLog();

                    task.AssignedTo     = assignee.AssigneeId;
                    task.Category_Id    = activity.Category_Id;
                    task.SubCategory_Id = activity.SubCategory_Id;
                    if (assignee.Quantity != null)
                    {
                        task.Subject = activity.Subject + " Quanity - " + assignee.Quantity;
                    }
                    else
                    {
                        task.Subject = activity.Subject;
                    }

                    task.TaskOwner     = assignee.AssigneeId;
                    task.Description   = activity.Description;
                    task.EDOC          = Convert.ToDateTime(activity.EDOC);
                    task.Status        = "Open";
                    task.TaskType      = activity.TaskType;
                    task.Client_Id     = activity.Client_Id;
                    task.Project_Id    = activity.Project_Id;
                    task.Priority      = activity.Priority;
                    task.CreatedBy     = User.Identity.GetUserId();
                    task.CreatedDate   = MasterDataController.GetIndianTime(DateTime.UtcNow);
                    task.ParentTask_Id = activity.TaskId;
                    if (assignee.Quantity != null)
                    {
                        task.Quantity = assignee.Quantity;
                    }
                    //else
                    //{
                    //    task.Quantity = null;
                    //}

                    task.TaskId = GenerateTaskId();

                    db.Activities.Add(task);
                    if (parentLog.Count() > 0)
                    {
                        for (int i = 0; i < parentLog.Count(); i++)
                        {
                            ActivitiesLog Log = new ActivitiesLog();

                            Log.Status         = parentLog[i].Status;
                            Log.Description    = parentLog[i].Description;
                            Log.TaskDate       = Convert.ToDateTime(parentLog[i].TaskDate);
                            Log.AssignedBy     = parentLog[i].AssignedById;
                            Log.AssignedTo     = parentLog[i].AssignedToId;
                            Log.HoursWorked    = parentLog[i].HoursWorked;
                            Log.QuantityWorked = parentLog[i].QuantityWorked;

                            task.ActivitiesLogs.Add(Log);
                        }
                    }

                    activityLog.Status      = task.Status;
                    activityLog.Description = task.Description;
                    activityLog.TaskDate    = MasterDataController.GetIndianTime(DateTime.UtcNow);
                    activityLog.AssignedBy  = task.CreatedBy;
                    activityLog.AssignedTo  = assignee.AssigneeId;
                    activityLog.TaskId      = activity.TaskId;

                    task.ActivitiesLogs.Add(activityLog);
                    db.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
                return(false);
            }
        }