public ActionResult Renew(Guid ClientID) { if (HasPermission("Renew Client")) { Client ToBeRenewd = ClientService.GetById(ClientID); try { ToBeRenewd.Status = "Activated"; ToBeRenewd.Expiry = DateTime.Now.AddMonths(1).Date; ToBeRenewd.IsExpiryNull = false; ClientService.SaveClient(); HubManPractices.Models.Action Renewal = new HubManPractices.Models.Action() { ActionID = Guid.NewGuid(), ActionName = "Renewal", Client = ToBeRenewd, Date = DateTime.Now }; ActionService.CreateAction(Renewal); return(RedirectToAction("Index", new { ResellerID = ToBeRenewd.ResellerID })); } catch (Exception ex) { TempData["RenewError"] = "Error in Renwal of the Client"; return(RedirectToAction("Index", new { ResellerID = ToBeRenewd.ResellerID })); } } return(View("~/Views/Home/UnAuthorized.cshtml")); }
public ActionResult Upgrade(FormCollection Fc) { if (HasPermission("Upgrade Client")) { Client client = ClientService.GetById(Guid.Parse(Fc["ClientUpgradeID"])); try { IEnumerable <OfficeSubscription> Subscriptions = SubscriptionService.GetAllSubscriptions(); client.IsExpiryNull = false; client.Seats += Int32.Parse(Fc["SeatsUpgrade"]); ClientService.SaveClient(); HubManPractices.Models.Action Upgrade = new HubManPractices.Models.Action() { ActionID = Guid.NewGuid(), ActionName = "Upgraded", Client = ClientService.GetById(client.ClientID), Date = DateTime.Now }; ActionService.CreateAction(Upgrade); } catch (DbUpdateException ex) { TempData["Upgrade Update Error"] = "Error while updating the entries"; return(RedirectToAction("Upgrade", new { ClientID = client.ClientID })); } catch (Exception ex) { TempData["Upgrade Error"] = "Error in function Upgrade"; return(RedirectToAction("Upgrade", new { ClientID = client.ClientID })); } TempData["Upgrade Success"] = "The Client has been Upgraded"; return(RedirectToAction("Index", new { ResellerID = client.ResellerID })); } return(View("~/Views/Home/UnAuthorized.cshtml")); }
public ActionResult Reactivate(FormCollection Fc) { Client ToReactivate = ClientService.GetClientByNameAndMail(Fc["ClientName"], Fc["ContactMail"]); ToReactivate.IsDeleted = false; ToReactivate.Status = "On Hold"; ToReactivate.Expiry = null; ToReactivate.IsExpiryNull = true; var i = 0; foreach (var Sub in ToReactivate.ClientSubscriptions) { ToReactivate.ClientSubscriptions.ElementAt(i).IsDeleted = false; i++; } try { ClientService.EditClient(ToReactivate); } catch (DbUpdateException ex) { TempData["ReActivateError"] = "Error in Readding the client again.."; return(RedirectToAction("Create", new { ResellerID = ToReactivate.ResellerID })); } HubManPractices.Models.Action Reactivate = new HubManPractices.Models.Action() { ActionID = Guid.NewGuid(), ActionName = "ReAactivated", Client = ToReactivate, Date = DateTime.Now }; ActionService.CreateAction(Reactivate); TempData["ReactivateClient"] = "The Client has been Reactivated"; return(RedirectToAction("Index", new { ResellerID = ToReactivate.ResellerID })); }
public void TestCreateAction() { //Arrange Guid id = Guid.NewGuid(); HubManPractices.Models.Action ToCreate = new HubManPractices.Models.Action() { ActionID = id, ActionName = "Terminate", Client = new Client() { ClientID = Guid.NewGuid(), ClientName = "Doha" }, Date = DateTime.Now }; //Act actionService.CreateAction(ToCreate); //Assert //Verifies the Action has been inserted Assert.AreEqual(id, actionService.GetById(id).ActionID); Assert.IsTrue(actionService.GetActions().Count() == 3); }
public ActionResult Delete(Guid ClientID) { if (HasPermission("Delete Client")) { Client ToBeDeleted = ClientService.GetById(ClientID); try { ClientService.DeleteClient(ToBeDeleted); HubManPractices.Models.Action Terminate = new HubManPractices.Models.Action() { ActionID = Guid.NewGuid(), ActionName = "Terminated", Client = ToBeDeleted, Date = DateTime.Now }; ActionService.CreateAction(Terminate); return(RedirectToAction("Index", new { ResellerID = ToBeDeleted.ResellerID })); } catch (Exception ex) { TempData["DeleteError"] = "Error in Deleting the Client"; return(RedirectToAction("Index", new { ResellerID = ToBeDeleted.ResellerID })); } } return(View("~/Views/Home/UnAuthorized.cshtml")); }
public ActionResult Suspend(Guid ClientID) { if (HasPermission("Suspend Client")) { Client ToBeSuspended = ClientService.GetById(ClientID); try { ToBeSuspended.Status = "Suspended"; ClientService.SaveClient(); HubManPractices.Models.Action Suspend = new HubManPractices.Models.Action() { ActionID = Guid.NewGuid(), ActionName = "Suspended", Client = ToBeSuspended, Date = DateTime.Now }; ActionService.CreateAction(Suspend); return(RedirectToAction("Index", new { ResellerID = ToBeSuspended.ResellerID })); } catch (Exception ex) { TempData["SuspendError"] = "Error in Suspending the Client"; return(RedirectToAction("Index", new { ResellerID = ToBeSuspended.ResellerID })); } } return(View("~/Views/Home/UnAuthorized.cshtml")); }
public async Task <ActionResult> SendEmail(FormCollection Fc) { if (EmailIsCorrectFormat(Fc["ContactMail"]) && Fc["ContactNumber"].ToString().Count() == 11) { if (ClientService.ClientNameAndMailExistsAndDeleted(Fc["ClientName"], Fc["ContactMail"])) { TempData["NameAndMailExistsAndDeleted"] = "The Client you are trying to add was deleted , Choose What To Do :"; Client client = new Client() { Expiry = null, IsExpiryNull = true, ClientName = Fc["ClientName"], ContactMail = Fc["ContactMail"], ContactName = Fc["ContactName"], ContactNumber = Int32.Parse(Fc["ContactNumber"]), ContactTitle = Fc["ContactTitle"], ResellerID = Guid.Parse(Fc["ResellerID"]), Seats = Int32.Parse(Fc["Seats"]), Location = Fc["Location"], CreationDate = DateTime.Now }; IEnumerable <OfficeSubscription> Subscriptions = SubscriptionsService.GetAllSubscriptions(); foreach (var Sub in Subscriptions) { string idx = Sub.MonthlyFee.ToString(); if (Fc[Sub.SubscriptionName] != "" && Fc[Sub.SubscriptionName] != "0") { client.ClientSubscriptions.Add(new ClientSubscriptions() { SubscriptionID = Guid.Parse(Fc[idx]), UsersPerSubscription = Int32.Parse(Fc[Sub.SubscriptionName]), OfficeSubscription = SubscriptionsService.GetById(Guid.Parse(Fc[idx])) }); } } return(View("~/Views/Client/Exist.cshtml", ClientService.MapToViewModel(client))); } try { Client client = new Client() { ClientID = Guid.NewGuid(), Expiry = null, IsExpiryNull = true, ClientName = Fc["ClientName"], ContactMail = Fc["ContactMail"], ContactName = Fc["ContactName"], ContactNumber = Int32.Parse(Fc["ContactNumber"]), ContactTitle = Fc["ContactTitle"], ResellerID = Guid.Parse(Fc["ResellerID"]) }; client.reseller = ResellerService.GetById(Guid.Parse(Fc["ResellerID"])); IEnumerable <OfficeSubscription> Subscriptions = SubscriptionsService.GetAllSubscriptions(); if (!ClientService.Exists(client)) { client.Seats = Int32.Parse(Fc["Seats"]); client.Status = "On Hold"; client.CreationDate = DateTime.Now; client.Location = Fc["Location"]; //UNCOMMENT when its available in PopUp .. /*foreach (var Sub in Subscriptions) * { * if (Fc[Sub.SubscriptionName] != "" && Fc[Sub.SubscriptionName] != "0") * { * string idx = Sub.MonthlyFee.ToString(); * client.ClientSubscriptions.Add(new ClientSubscriptions() { ClientID = client.ClientID, SubscriptionID = Guid.Parse(Fc[idx]), UsersPerSubscription = Int32.Parse(Fc[Sub.SubscriptionName]) }); * } * }*/ ClientService.CreateClient(client); HubManPractices.Models.Action OnHold = new HubManPractices.Models.Action() { ActionID = Guid.NewGuid(), ActionName = "On Hold", Client = client, Date = DateTime.Now }; ActionService.CreateAction(OnHold); } else { TempData["Exists"] = "This Client is already added in the system"; return(RedirectToAction("Create", "Client", new { ResellerID = Guid.Parse(Fc["ResellerID"]) })); } ApplicationUser LoggedInUser = UserManager.FindById(User.Identity.GetUserId()); IEnumerable <ApplicationUser> GlobalAdmins = roleService.GetUserInRole("Global Admin"); foreach (var global in GlobalAdmins) { string Body = String.Format("Dear {0}, <br />" + "The Client {1} has been added to your system by Reseller {2} <br /> " + "Please Click {3}", global.UserName, client.ClientName, User.Identity.GetUserName(), "<a href='http://localhost:41301/Client?ResellerID=" + LoggedInUser.ResellerID + "'>here</a>"); await UserManager.SendEmailAsync(global.Id, "Client is Added ", Body); } TempData["Create Success"] = "Client Created Successfully"; return(RedirectToAction("ResellerIndex", "Reseller", new { ResellerID = Guid.Parse(Fc["ResellerID"]) })); } catch (DbUpdateException ex) { TempData["Exists"] = "Contact Mail Can not be repeated"; return(RedirectToAction("Create", "Client", new { ResellerID = Guid.Parse(Fc["ResellerID"]) })); } catch (Exception ex) { TempData["ErrorCreate"] = "Error in adding Client"; return(RedirectToAction("ResellerIndex", "Reseller", new { ResellerID = Guid.Parse(Fc["ResellerID"]) })); } } else { if (!EmailIsCorrectFormat(Fc["ContactMail"])) { TempData["EmailWrongFormhat"] = "The E-mail You entered is not in the correct format"; return(RedirectToAction("Create", "Client", new { ResellerID = Guid.Parse(Fc["ResellerID"]) })); } else { TempData["NumberWrongFormat"] = "The Contact Number You entered is not a Mobile Number"; return(RedirectToAction("Create", "Client", new { ResellerID = Guid.Parse(Fc["ResellerID"]) })); } } }