public async Task <IHttpActionResult> ForgotPassword(string email)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(email))
                {
                    return(Content(System.Net.HttpStatusCode.InternalServerError, "Please enter a valid email address"));
                }
                var user = await UserManager.FindByEmailAsync(email);

                if (user == null)
                {
                    return(Content(System.Net.HttpStatusCode.InternalServerError, "Sorry, we can't recognize that email."));
                }

                var provider = new MachineKeyProtectionProvider();
                UserManager.UserTokenProvider = new DataProtectorTokenProvider <ApplicationUser>(provider.Create("ForgotPassword"));

                var code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                code = HttpUtility.UrlEncode(code);
                var    userId      = HttpUtility.UrlEncode(user.Id);
                var    callbackUrl = ConfigurationManager.AppSettings["AppUrl"] + "#/reset-password/" + userId + "/" + code;
                string to          = user.Email;//user.Email;
                string subject     = "Reset Account password for MAX";
                string body        = "Please reset your password by clicking here: <a href=" + callbackUrl + ">Reset Password</a>";
                string from        = "*****@*****.**";

                bool mailSent = new EmailController().SendEmail(from, "", to, subject, body);

                if (!mailSent)
                {
                    return(Content(System.Net.HttpStatusCode.InternalServerError, "Error occoured while sending mail please try again later!"));
                }
                return(Ok());
            }

            catch (Exception ex)
            {
                new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
                return(Content(System.Net.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"));
            }
        }
예제 #4
0
        //public IHttpActionResult GetClientWithAspNetUserId(string clientId)
        //{
        //    try
        //    {
        //        using (MaxMasterDbEntities db = new MaxMasterDbEntities())
        //        {
        //            var client = db.Clients.Where(x => x.AspNetUserId == clientId).Select(x => new { value = x.AspNetUserId, label = x.ShortName }).FirstOrDefault();
        //            return Content(HttpStatusCode.OK, new { client });
        //        }
        //    }
        //    catch(Exception ex)
        //    {
        //        return Content(HttpStatusCode.InternalServerError, "An error occured, please try again later");
        //    }
        //}

        public async Task <IHttpActionResult> AddClientWithPwd()
        {
            try
            {
                UserManager <ApplicationUser> userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var form            = HttpContext.Current.Request.Form;
                    var clientLocations = JsonConvert.DeserializeObject <List <ClientLocationModel> >(form.Get("ClientLocations"));
                    var email           = form.Get("Email");
                    var password        = form.Get("password");
                    var userName        = form.Get("userName");

                    var user1 = userManager.FindByEmail(email);
                    if (user1 != null)
                    {
                        return(Content(HttpStatusCode.InternalServerError, "User with email " + email + " already exists"));
                    }

                    var exsistingUser = await _userManager.FindByNameAsync(userName);

                    if (exsistingUser != null)
                    {
                        return(Content(HttpStatusCode.InternalServerError, "User with user name " + userName + " already exists"));
                    }

                    Client client = new Client();

                    client.OrgId        = Convert.ToInt32(form.Get("Organisation"));
                    client.Name         = form.Get("Name");
                    client.ShortName    = form.Get("ShortName");
                    client.Email        = email;
                    client.PrimaryPhone = form.Get("PrimaryPhone");

                    for (int i = 0; i < clientLocations.Count; i++)
                    {
                        ClientLocation clientloc = new ClientLocation();
                        clientloc.AddressLine1     = clientLocations[i].AddressLine1;
                        clientloc.AddressLine2     = clientLocations[i].AddressLine2;
                        clientloc.Landmark         = clientLocations[i].Landmark;
                        clientloc.Country_Id       = clientLocations[i].Country;
                        clientloc.State_Id         = clientLocations[i].State;
                        clientloc.City_Id          = clientLocations[i].City;
                        clientloc.ZIP              = clientLocations[i].zip;
                        clientloc.TimeZone_Id      = clientLocations[i].TimeZone;
                        clientloc.IsInvoiceAddress = clientLocations[i].IsInvoice;
                        clientloc.Client_Id        = client.Id;

                        client.ClientLocations.Add(clientloc);
                    }

                    ApplicationUser user = new ApplicationUser()
                    {
                        UserName = userName, Email = email
                    };

                    _userManager.UserValidator = new UserValidator <ApplicationUser>(_userManager)
                    {
                        AllowOnlyAlphanumericUserNames = false,
                        RequireUniqueEmail             = true
                    };
                    IdentityResult result = _userManager.Create(user, password);

                    if (!result.Succeeded)
                    {
                        return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later"));
                    }

                    var roleStore   = new RoleStore <IdentityRole>(appDb);
                    var roleManager = new RoleManager <IdentityRole>(roleStore);

                    _userManager.AddToRole(user.Id, "Client");

                    string to      = email;
                    string subject = "Welcome to Max Trans Systems";
                    string body    = "Hi,Welcome to Max Trans Systems. Following are the credentials for your account" +
                                     Environment.NewLine + "Username : "******"Password : "******"*****@*****.**";

                    var sendMail = new EmailController().SendEmail(from, "Max", email, subject, body);

                    client.AspNetUserId = user.Id;
                    client.Active       = true;
                    client.LastUpdated  = DateTime.Now;
                    client.UpdatedBy    = User.Identity.GetUserId();
                    client.ClientType   = "Direct Client";

                    db.Clients.Add(client);
                    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 occoured, please try again!"));
            }
        }