public ActionResult SecureAccount(UIAccount_S uim) { AjaxStatus status = new AjaxStatus(); using (var context = new DataContext()) { try { Account dbm = AccountOperations.TryRead(Account.EMPTY_ACCOUNT, context, uim.email); dbm = uim.UpdateModel(dbm); if (AccountOperations.TrySecure(Account.EMPTY_ACCOUNT, context, dbm, uim.PIN)) { SetLoginAccount(dbm); status.nextURL = "/Home"; } else { uim.ResetModel(dbm); status.SetError("Felaktig eller för gammal PIN-kod"); } context.SaveChanges(); } catch (Exception e) { base.HandleException("SecureAccount", e); status.SetError(e.Message); } } return(Json(status)); }
public ActionResult ValidateAccount(UIAccount_V uim) { AjaxStatus status = new AjaxStatus(); using (var context = new DataContext()) { try { Account dbm = LoginOperations.TryRead(Account.EMPTY_ACCOUNT, context, uim.email); dbm = LoginOperations.TryValidate(dbm, context, uim.password); if (dbm == null) { status.SetError("Felaktig användare eller lösenord"); } else { SetLoginAccount(dbm); status.nextURL = "/Home"; } context.SaveChanges(); } catch (Exception e) { base.HandleException("ValidateAccount", e); status.SetError(e.Message); } } return(Json(status)); }
public ActionResult CreateIssue(UIIssue_C uim) { AjaxStatus status = new AjaxStatus(); using (var context = new DataContext()) { using (var transaction = context.Database.BeginTransaction()) { try { Account account = base.GetLoginAccount(); Issue dbm = uim.CreateModel(); IssueOperations.TryCreate(account, context, dbm); context.SaveChanges(); IssueTransition transition = uim.CreateModel(dbm, account); IssueTransitionOperations.TryCreate(account, context, transition); context.SaveChanges(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); base.HandleException("CreateIssue", e); status.SetError(e.Message); } } } return(Json(status)); }
public ActionResult RescheduleIssue(UIIssueSchedule_U uim) { AjaxStatus status = new AjaxStatus(); using (var context = new DataContext()) { try { Account account = base.GetLoginAccount(); Issue dbm = IssueOperations.TryRead(account, context, uim.id); // Update model uim.UpdateModel(dbm); IssueOperations.TryUpdate(account, context, dbm); // Mark as unread IssueOperations.TryDeleteReaders(account, context, dbm.id); context.SaveChanges(); } catch (Exception e) { base.HandleException("RescheduleIssue", e); status.SetError(e.Message); } } return(Json(status)); }
public ActionResult UpdateIssueStatus(UIIssueStatus_U uim) { AjaxStatus status = new AjaxStatus(); using (var context = new DataContext()) { using (var transaction = context.Database.BeginTransaction()) { try { Account account = base.GetLoginAccount(); Issue dbm = IssueOperations.TryRead(account, context, uim.id); // Create transition IssueTransition transition = uim.CreateModel(dbm, account); IssueTransitionOperations.TryCreate(account, context, transition); // Update model uim.UpdateModel(dbm); IssueOperations.TryUpdate(account, context, dbm); // Mark as unread IssueOperations.TryDeleteReaders(account, context, dbm.id); // TODO: If new status is to archive, move to archived tables context.SaveChanges(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); base.HandleException("UpdateIssueStatus", e); status.SetError(e.Message); } } } return(Json(status)); }
public ActionResult SyncTimeTypes() { AjaxStatus status = new AjaxStatus(); using (var context = new DataContext()) { try { Account account = base.GetLoginAccount(); // Fake code: context.TimeTypes.RemoveRange(context.TimeTypes.ToList()); IList <TimeType> addons = new List <TimeType>(10); addons.Add(new TimeType { code = "003", name = "Arbetskostnad", unit = "Tim", description = "Vardagar 07-19", active = TimeType.ACTIVE }); addons.Add(new TimeType { code = "008", name = "Materialkostnad", unit = "Kr", description = "Per enhet", active = TimeType.ACTIVE }); addons.Add(new TimeType { code = "011", name = "Förvaltare", unit = "Tim", description = "Timdebitering ex raster", active = TimeType.ACTIVE }); addons.Add(new TimeType { code = "020", name = "Miljö- och deponeringsavgift", unit = "Kr", description = "Vardagar 07-19", active = TimeType.ACTIVE }); addons.Add(new TimeType { code = "022", name = "Tippavgift", unit = "Kr", description = "Sörab Väsby/Smedby", active = TimeType.INACTIVE }); addons.Add(new TimeType { code = "021", name = "Underentreprenör", unit = "Kr", description = "Fast pris", active = TimeType.ACTIVE }); addons.Add(new TimeType { code = "030", name = "Felsökning", unit = "Tim", description = "Vardagar 07-19", active = TimeType.ACTIVE }); addons.Add(new TimeType { code = "033", name = "Jour", unit = "Tim", description = "Helger och kvällar", active = TimeType.ACTIVE }); addons.Add(new TimeType { code = "036", name = "Besiktning", unit = "St", description = "Per tillfälle", active = TimeType.ACTIVE }); addons.Add(new TimeType { code = "037", name = "Arbetsmaskin/Traktor", unit = "Tim", description = "Alla tider", active = TimeType.ACTIVE }); context.TimeTypes.AddRange(addons); // TODO: //TimeType model = uim.CreateModel(); //TimeTypeOperations.TryCreate(account, context, model); context.SaveChanges(); } catch (Exception e) { base.HandleException("CreateTimeType", e); status.SetError(e.Message); } } return(Json(status)); }
public ActionResult CreateAccount(UIAccount_C uim) { AjaxStatus status = new AjaxStatus(); using (var context = new DataContext()) { try { Account model = uim.CreateModel(); RegisterOperations.TryCreate(Account.EMPTY_ACCOUNT, context, model); context.SaveChanges(); } catch (Exception e) { base.HandleException("CreateAccount", e); status.SetError(e.Message); } } return(Json(status)); }
public ActionResult ResendPIN(string email) { AjaxStatus status = new AjaxStatus(); using (var context = new DataContext()) { try { Account dbm = AccountOperations.TryRead(Account.EMPTY_ACCOUNT, context, email); AccountOperations.TryResendPIN(Account.EMPTY_ACCOUNT, context, dbm); context.SaveChanges(); } catch (Exception e) { base.HandleException("ResendPIN", e); status.SetError(e.Message); } } return(Json(status)); }
public ActionResult DeleteOffer(int id) { AjaxStatus status = new AjaxStatus(); using (var context = new DataContext()) { try { Account account = base.GetLoginAccount(); OfferOperations.TryDelete(account, context, id); context.SaveChanges(); } catch (Exception e) { base.HandleException("DeleteOffer", e); status.SetError(e.Message); } } return(Json(status)); }
public ActionResult ForgotAccount(UIAccount_F uim) { AjaxStatus status = new AjaxStatus(); using (var context = new DataContext()) { try { Account dbm = uim.CreateModel(); Account requester = LoginOperations.TryRead(Account.EMPTY_ACCOUNT, context, dbm.email); LoginOperations.TrySendPIN(requester, context, Account.EMPTY_ACCOUNT); context.SaveChanges(); } catch (Exception e) { base.HandleException("ForgotAccount", e); status.SetError(e.Message); } } return(Json(status)); }
public ActionResult CreateCustomer(UICustomer_CRU uim) { AjaxStatus status = new AjaxStatus(); using (var context = new DataContext()) { try { Account account = base.GetLoginAccount(); Customer model = uim.CreateModel(); CustomerOperations.TryCreate(account, context, model); context.SaveChanges(); } catch (Exception e) { base.HandleException("CreateCustomer", e); status.SetError(e.Message); } } return(Json(status)); }
public ActionResult CreateBugReport(UIBugReport_C uim) { AjaxStatus status = new AjaxStatus(); using (var context = new DataContext()) { try { Account account = base.GetLoginAccount(); BugReport model = uim.CreateModel(); BugReportOperations.TryCreate(account, context, model); SendBugReport(account, model, status); } catch (Exception e) { base.HandleException("CreateBugReport", e); status.SetError(e.Message); } } return(Json(status)); }
public ActionResult CreateIssueFeedback(UIIssueFeedback_C uim) { AjaxStatus status = new AjaxStatus(); using (var context = new DataContext()) { try { Account account = base.GetLoginAccount(); IssueFeedback model = uim.CreateModel(account); IssueFeedbackOperations.TryCreate(account, context, model); context.SaveChanges(); } catch (Exception e) { base.HandleException("CreateIssueFeedback", e); status.SetError(e.Message); } } return(Json(status)); }
public void SendBugReport(Account requester, BugReport bugreport, AjaxStatus status) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(GITAPI); request.Headers.Add("Authorization", string.Format("token {0}", TOKEN)); request.Method = "POST"; request.ContentType = "application/json"; request.Accept = "application/json"; request.UserAgent = ACCOUNT; try { using (var streamWriter = new StreamWriter(request.GetRequestStream())) { var jsonString = new JavaScriptSerializer().Serialize(new { title = bugreport.headline, body = bugreport.description + "\n\n[" + requester.Name + "]", labels = new List <String>(new string[] { LABEL }) }); streamWriter.Write(jsonString); streamWriter.Flush(); streamWriter.Close(); } var response = request.GetResponse(); using (var streamReader = new StreamReader(response.GetResponseStream())) { var deserializer = new JavaScriptSerializer(); var result = streamReader.ReadToEnd(); var dict = deserializer.Deserialize <Dictionary <string, object> >(result); status.data1 = "Ärende: " + dict["number"]; status.data2 = "Rubrik: " + dict["title"]; } } catch (Exception e) { TraceLog.Instance.LogError("SendBugReport() " + e.ToString()); throw new ServerConflictException("Kunde inte skapa felanmälan, kontakta oss via e-post"); } }
public ActionResult UpdateOffer(UIOffer_CRU uim) { AjaxStatus status = new AjaxStatus(); using (var context = new DataContext()) { try { Account account = base.GetLoginAccount(); Offer dbm = OfferOperations.TryRead(account, context, uim.id); dbm = uim.UpdateModel(dbm, account); OfferOperations.TryUpdate(account, context, dbm); context.SaveChanges(); } catch (Exception e) { base.HandleException("UpdateOffer", e); status.SetError(e.Message); } } return(Json(status)); }
public ActionResult UpdateIssue(UIIssueProblem_U uim) { AjaxStatus status = new AjaxStatus(); using (var context = new DataContext()) { try { Account account = base.GetLoginAccount(); Issue dbm = IssueOperations.TryRead(account, context, uim.issueid); dbm = uim.UpdateModel(dbm); IssueOperations.TryUpdate(account, context, dbm); context.SaveChanges(); } catch (Exception e) { base.HandleException("UpdateIssue", e); status.SetError(e.Message); } } return(Json(status)); }
public ActionResult ChangePassword(UIEmployee_S uim) { AjaxStatus status = new AjaxStatus(); using (var context = new DataContext()) { try { Account account = base.GetLoginAccount(); Account dbm = EmployeeOperations.TryRead(account, context, uim.id); dbm = uim.UpdateModel(dbm); EmployeeOperations.TryUpdate(account, context, dbm); context.SaveChanges(); } catch (Exception e) { base.HandleException("ChangePassword", e); status.SetError(e.Message); } } return(Json(status)); }
public ActionResult UpdateProfile(UIProfile_RU uim) { AjaxStatus status = new AjaxStatus(); using (var context = new DataContext()) { try { Account account = base.GetLoginAccount(); Account dbm = ProfileOperations.TryRead(account, context, account.id); dbm = uim.UpdateModel(dbm); ProfileOperations.TryUpdate(account, context, dbm); context.SaveChanges(); base.SetLoginAccount(dbm); } catch (Exception e) { base.HandleException("UpdateProfile", e); status.SetError(e.Message); } return(Json(status)); } }