public ActionResult LogOff() { logger.Info(Environment.NewLine + "User logged out: " + CookieHandler.GetUserNameFromCookie("LoginCookie") + " " + DateTime.Now); CookieHandler.DeleteCookie("LoginCookie"); return(RedirectToAction("Login", "Login")); }
public ActionResult DeleteRecipient(string id) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(Request.Url.GetLeftPart(UriPartial.Authority)); var deleteTask = client.DeleteAsync("api/Recipient/" + id); deleteTask.Wait(); var result = deleteTask.Result; if (result.IsSuccessStatusCode) { logger.Info(Environment.NewLine + "Recipient " + id + " deleted by " + CookieHandler.GetUserNameFromCookie("LoginCookie") + " " + DateTime.Now); return(RedirectToAction("RecipientIndex")); } } TempData["error"] = "Cannot delete. Recipient used in invoice."; return(RedirectToAction("RecipientIndex")); }
public ActionResult CreateRecipient(RecipientViewModel recipient) { PopulateList(); if (CheckIfDuplicatedId(recipient)) { return(RedirectToAction("RecipientIndex")); } try { if (ModelState.IsValid) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(Request.Url.GetLeftPart(UriPartial.Authority)); var postTask = client.PostAsJsonAsync <RecipientViewModel>("api/recipient", recipient); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { logger.Info(Environment.NewLine + "Recipient " + recipient.RecipientId.ToString() + " added by " + CookieHandler.GetUserNameFromCookie("LoginCookie") + " " + DateTime.Now); return(RedirectToAction("RecipientIndex")); } } } } catch (DataException) { ModelState.AddModelError(string.Empty, "Cannot create recipient"); } PopulateList(); return(View(recipient)); }
public virtual void Update(TEntity entityToUpdate) { dbSet.Attach(entityToUpdate); context.Entry(entityToUpdate).State = EntityState.Modified; logger.Info(Environment.NewLine + entityToUpdate.GetType().Name + " ID: " + GetPropValue(entityToUpdate, entityToUpdate.GetType().GetProperties()[0].Name) + " editted by " + CookieHandler.GetUserNameFromCookie("LoginCookie") + " " + DateTime.Now); }
public ActionResult EditRecipient(RecipientViewModel recipient) { recipient.CountryList = Recipient.CountryList; try { if (ModelState.IsValid) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(Request.Url.GetLeftPart(UriPartial.Authority)); var putTask = client.PutAsJsonAsync <RecipientViewModel>("api/Recipient", recipient); putTask.Wait(); var result = putTask.Result; if (result.IsSuccessStatusCode) { logger.Info(Environment.NewLine + "Recipient " + recipient.RecipientId + " editted by " + CookieHandler.GetUserNameFromCookie("LoginCookie") + " " + DateTime.Now); return(RedirectToAction("RecipientIndex")); } } } }catch (DataException) { } PopulateList(); return(View(recipient)); }
public virtual void Delete(object id) { TEntity entityToDelete = dbSet.Find(id); logger.Info(Environment.NewLine + entityToDelete.GetType().Name + " ID: " + GetPropValue(entityToDelete, entityToDelete.GetType().GetProperties()[0].Name) + " deleted by " + CookieHandler.GetUserNameFromCookie("LoginCookie") + " " + DateTime.Now); Delete(entityToDelete); }
public virtual void Insert(TEntity entity) { dbSet.Add(entity); logger.Info(Environment.NewLine + entity.GetType().Name + " ID: " + GetPropValue(entity, entity.GetType().GetProperties()[0].Name) + " added by " + CookieHandler.GetUserNameFromCookie("LoginCookie") + " " + DateTime.Now); }
public ActionResult CreateCountry(CountryViewModel country) { if (CheckIfDuplicatedId(country)) { return(RedirectToAction("CountryIndex")); } try { if (ModelState.IsValid) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(Request.Url.GetLeftPart(UriPartial.Authority)); var postTask = client.PostAsJsonAsync <CountryViewModel>("api/country", country); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { logger.Info(Environment.NewLine + "Country" + country.CountryId.ToString() + " added by " + CookieHandler.GetUserNameFromCookie("LoginCookie") + " " + DateTime.Now); return(RedirectToAction("CountryIndex")); } } } } catch (DataException) { ModelState.AddModelError(string.Empty, "Server Error."); } ModelState.AddModelError(string.Empty, "Cannot create country"); return(View(country)); }
public ActionResult EditCountry(CountryViewModel country) { try { if (ModelState.IsValid) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(Request.Url.GetLeftPart(UriPartial.Authority)); var putTask = client.PutAsJsonAsync <CountryViewModel>("api/country", country); putTask.Wait(); var result = putTask.Result; if (result.IsSuccessStatusCode) { logger.Info(Environment.NewLine + "Country" + country.CountryId.ToString() + " edited by " + CookieHandler.GetUserNameFromCookie("LoginCookie") + " " + DateTime.Now); return(RedirectToAction("CountryIndex")); } } } }catch (DataException) { } return(View(country)); }
public ActionResult EditSupplier(SupplierViewModel supplier) { try { if (ModelState.IsValid) { supplier.CountryList = Supplier.CountryList; using (var client = new HttpClient()) { client.BaseAddress = new Uri(Request.Url.GetLeftPart(UriPartial.Authority)); var putTask = client.PutAsJsonAsync <SupplierViewModel>("api/Supplier", supplier); putTask.Wait(); var result = putTask.Result; if (result.IsSuccessStatusCode) { logger.Info(Environment.NewLine + "Supplier " + supplier.SupplierId + " edited by " + CookieHandler.GetUserNameFromCookie("LoginCookie") + " " + DateTime.Now); return(RedirectToAction("SupplierIndex")); } } } } catch (DataException) { } PopulateList(); return(View(supplier)); }