Example #1
0
        public async Task <IActionResult> Edit(int id, ContactPersonCreateViewModel personVM)
        {
            try
            {
                if (id.ToString() != personVM.ContactId)
                {
                    return(Json(JsonResponse.Error("The contact person do not found", null, MessageInfoType.Error)));
                }

                if (ModelState.IsValid)
                {
                    var user = Mapper.Map <MS_PIC>(personVM);

                    var row = await ContPersonService.Update(user);

                    if (row == 0)
                    {
                        return(Json(JsonResponse.Success("No data updated", null, MessageInfoType.Info)));
                    }
                    else
                    {
                        return(Json(JsonResponse.Success("The user was successfully updated", null, MessageInfoType.Success)));
                    }
                }

                return(Json(JsonResponse.Error("Insufficient data", null, MessageInfoType.Error)));
            }
            catch (Exception ex)
            {
                return(Json(JsonResponse.Error(ex.Message, null, MessageInfoType.Error)));
            }
        }
        public ActionResult Distribution([FromServices] InMemoryDataContext context, [FromBody] DistributionRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var useCase = new UseCase(
                    _logger,
                    new EmployeeAdapter(context),
                    new CalculationInfluenceAdapter(
                        new AreaCalculator(),
                        new SalaryCalculator(),
                        new AdmissionAtCalculator()
                        )
                    );
                var response = useCase.Execute(new Request(
                                                   request.AvailableValue
                                                   ));
                return(JsonResponse.Success((new DistributionPresenter(response)).Present()));
            }
            catch (InsufficientAvailableValueException exception)
            {
                return(JsonResponse.Error(exception.Message, 400));
            }
            catch (System.Exception exception)
            {
                return(JsonResponse.Error(exception.Message));
            }
        }
Example #3
0
        public async Task <IActionResult> LoginAjax(LoginViewModel model)
        {
            string resp = string.Empty;

            try
            {
                var user = await UserService.AuthenticateUser(model.UserName, model.Password);

                if (user == null)
                {
                    return(Json(JsonResponse.Error("Invalid Username or Password", null, MessageInfoType.Error)));
                }

                var claims = new[] {
                    new Claim(ClaimTypes.NameIdentifier, user.IUserId ?? ""),
                    new Claim(ClaimTypes.Name, user.IUserName ?? ""),
                    new Claim(ClaimTypes.Email, user.IMail ?? ""),
                    new Claim(ClaimTypes.Role, user.RoleText ?? ""),
                    new Claim("VendorCode", user.IVsCd ?? ""),
                    new Claim("CompanyName", user.MS_VS.IVsDesc ?? "")
                };

                var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);

                await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity));

                resp = JsonResponse.Success("Login Successfully", null, MessageInfoType.Success);
            } catch (Exception ex) {
                resp = JsonResponse.Error("Login Failure", ex.ToString(), MessageInfoType.Error);
            }
            return(Json(resp));
        }
Example #4
0
        public async Task <IActionResult> DeleteConfirmed(string id)
        {
            try
            {
                if (string.IsNullOrEmpty(id.ToString()))
                {
                    return(Json(JsonResponse.Error("Contact person Not found", null, MessageInfoType.Error)));
                }

                int.TryParse(id, out int conId);
                var row = await ContPersonService.DeleteById(conId);

                if (row == 0)
                {
                    return(Json(JsonResponse.Success("No data deleted", null, MessageInfoType.Info)));
                }
                else
                {
                    return(Json(JsonResponse.Success("The contact person was successfully deleted", null, MessageInfoType.Success)));
                }
            }
            catch (Exception ex)
            {
                return(Json(JsonResponse.Success(ex.Message, null, MessageInfoType.Error)));
            }
        }
Example #5
0
        public async Task <IActionResult> Create(ContactPersonCreateViewModel personVM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var person = Mapper.Map <MS_PIC>(personVM);

                    var row = await ContPersonService.Add(person);

                    if (row == 0)
                    {
                        return(Json(JsonResponse.Success("No data created", null, MessageInfoType.Info)));
                    }
                    else
                    {
                        return(Json(JsonResponse.Success("The contact person was successfully created", null, MessageInfoType.Success)));
                    }
                }

                return(Json(JsonResponse.Error("Insufficient data", null, MessageInfoType.Error)));
            }
            catch (Exception ex)
            {
                return(Json(JsonResponse.Error(ex.Message, null, MessageInfoType.Error)));
            }
        }
        public async Task <IHttpActionResult> AddComment(TaskCommentViewModel model)
        {
            try
            {
                //add task owner to model
                if (string.IsNullOrWhiteSpace(model.CommentBody))
                {
                    return(Json(JsonResponse.Error("Please input a comment.")));
                }
                UserTaskCommentBO userTaskComment = new UserTaskCommentBO
                {
                    UserTaskId  = model.UserTaskId,
                    Comment     = model.CommentBody,
                    CommenterId = CurrentUserId,
                    CommentDate = DateTime.UtcNow,
                    Audit       = new Entity.Entities.Audit(CurrentUserId)
                };
                zeus.evaluationManager.Add(userTaskComment);
                await AddNotificationAsync(NotificationType.NewTaskComment, CurrentUserId, model.UserId, "task/" + model.UserTaskId);

                return(Ok(new UserTaskCommentDTO {
                    UserTaskCommentId = userTaskComment.Id, CommenterId = CurrentUserId, Comment = model.CommentBody, CommenterName = "You", Date = DateTime.UtcNow
                }));
            }
            catch (Exception ex)
            {
                LogError(ex, CurrentUserId);
                return(BadRequest());
            }
        }
Example #7
0
        public async Task <IActionResult> ChangePasswordAsync(ChangePasswordViewModel passVM)
        {
            try
            {
                if (string.IsNullOrEmpty(passVM.OldPassword) || string.IsNullOrEmpty(passVM.NewPassword) ||
                    (passVM.NewPassword != passVM.ConfirmPassword))
                {
                    return(Json(JsonResponse.Error("Confirm Password do not match", null, MessageInfoType.Error)));
                }

                var user = await UserService.AuthenticateUser(UserResolverService.UserID, passVM.OldPassword);

                if (user == null)
                {
                    return(Json(JsonResponse.Error("Invalid User or Password", null, MessageInfoType.Error)));
                }

                user.IUserPwd  = BCrypt.Net.BCrypt.HashPassword(passVM.NewPassword);
                user.IResetPin = null;
                var row = await UserService.Update(user);

                if (row == 0)
                {
                    return(Json(JsonResponse.Success("No data updated", null, MessageInfoType.Info)));
                }
                else
                {
                    return(Json(JsonResponse.Success("Your password was successfully changed", null, MessageInfoType.Success)));
                }
            }
            catch (Exception ex)
            {
                return(Json(JsonResponse.Error(ex.InnerException.Message, null, MessageInfoType.Error)));
            }
        }
Example #8
0
        public string DoLogin([FromBody] AuthLoginViewModel model)
        {
            List <DB.User> user;

            using (ApplicationContext db = new ApplicationContext())
            {
                user = db.Users.Where(a => a.Email == model.Email && a.Password == HashPassword(model.Password)).ToList();
            }

            if (user.Count == 0)
            {
                return(JsonResponse.Error("incorrect login or password"));
            }
            else
            {
                Response.Cookies.Append("Email", model.Email, new Microsoft.AspNetCore.Http.CookieOptions()
                {
                    Path = "/", Expires = DateTimeOffset.Now.AddDays(7)
                });
                Response.Cookies.Append("Session", GetNewSession(model.Email), new Microsoft.AspNetCore.Http.CookieOptions()
                {
                    Path = "/", Expires = DateTimeOffset.Now.AddDays(7)
                });
                if (user[0].Role == "admin")
                {
                    Response.Cookies.Append("IsAdmin", "it`s a secret!", new Microsoft.AspNetCore.Http.CookieOptions()
                    {
                        Path = "/", Expires = DateTimeOffset.Now.AddDays(7)
                    });
                }
                return(JsonResponse.Success());
            }
        }
Example #9
0
        public async Task <IActionResult> ForgetPasswordAsync(string userId)
        {
            try
            {
                var user = await UserService.GetUserById(userId);

                if (user == null)
                {
                    return(Json(JsonResponse.Error("Invalid User name", null, MessageInfoType.Error)));
                }

                if (string.IsNullOrEmpty(user.IMail))
                {
                    return(Json(JsonResponse.Error(@"Your email not found. 
                                                        Please contact your system administrator", null, MessageInfoType.Error)));
                }

                var resp = await UserService.ForgetPassword(user);

                if (resp)
                {
                    return(Json(JsonResponse.Success(@"Password Reset request was send successfully. 
                                                Please check your email to reset your password", null, MessageInfoType.Success)));
                }
                else
                {
                    return(Json(JsonResponse.Error(null, "", MessageInfoType.Error)));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
 public ActionResult UpdateUserRoles(UserRoleViewModel model)
 {
     try
     {
         bool clearRoles = RemoveAllUserRoles(model.UserId);
         if (clearRoles)
         {
             bool addToRoles = AddUserToRoles(model.UserId, model.UserRoles);
             if (!addToRoles)
             {
                 return(Json(JsonResponse.Error("Please try again")));
             }
             return(Json(JsonResponse.Success("User Roles Updated")));
         }
         else
         {
             return(Json(JsonResponse.Error("An Error occured, Please try again")));
         }
     }
     catch (Exception ex)
     {
         LogError(ex, CurrentUserId);
         return(Json(JsonResponse.Error("An Error occured, Please try again")));
     }
 }
Example #11
0
 public static string Save(
     int courseId,
     short type,
     string title,
     string description,
     bool enabled,
     string startPage,
     int?width,
     int?height,
     string extra1,
     string extra2
     )
 {
     try
     {
         lms_Entities db  = new ClientDBEntities();
         Course       crs = db.Courses.Where(c => c.courseId == courseId).FirstOrDefault();
         crs.type          = type;
         crs.title         = title;
         crs.description   = description;
         crs.enabled       = enabled;
         crs.url           = Global.WEBSITE_COURSES_FOLDER + "/" + LmsUser.companyFolder + "/" + courseId + "/" + startPage;
         crs.browserWidth  = width;
         crs.browserHeight = height;
         crs.extra1        = extra1;
         crs.extra2        = extra2;
         db.SaveChanges();
         return(JsonResponse.NoError);
     }
     catch (Exception e)
     {
         return(JsonResponse.Error(e));
     }
 }
Example #12
0
        public static string Delete(int?courseId)
        {
            try
            {
                //delete db entry
                lms_Entities db  = new ClientDBEntities();
                Course       crs = db.Courses.Where(c => c.courseId == courseId).FirstOrDefault();
                db.Courses.Remove(crs);
                db.SaveChanges();

                //delete files
                string courseAbsPath = Path.Combine(new string[] {
                    HttpContext.Current.Server.MapPath("~/" + Global.WEBSITE_COURSES_FOLDER),
                    LmsUser.companyFolder,
                    courseId.ToString()
                });
                if (Directory.Exists(courseAbsPath))
                {
                    Directory.Delete(courseAbsPath, true);
                }

                //all ok
                return(JsonResponse.NoError);
            }
            catch (Exception e)
            {
                return(JsonResponse.Error(e));
            }
        }
Example #13
0
        public async Task <JsonResult> SendConfirmationToEmail(string email)
        {
            //check if it's org email
            if (RegexExtension.IsValidEmail(email))
            {
                UserBO user = await UserManager.FindByEmailAsync(email);

                if (user == null)
                {
                    return(Json(JsonResponse.Success("Please Check your email to Reset your Password")));
                }
                if (user.EmailConfirmed == true)
                {
                    return(Json(JsonResponse.Success("Your Email has been Confirmed")));
                }

                try
                {
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    string callbackUrl = Url.Action("confirm", "account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    string emailBody   = await CreateEmailBodyAsync("../EmailTemplates/AccountConfirmation.html", user.Email, user.FirstName, callbackUrl, "");

                    await UserManager.SendEmailAsync(user.Id, "SiriusPM Account Confimation", emailBody);

                    return(Json(JsonResponse.Success("Please Check your email to Reset your Password")));
                }
                catch (Exception ex)
                {
                    LogError(ex, string.Empty);
                    return(Json(JsonResponse.Error("Unsuccesfull")));
                }
            }
            return(Json(JsonResponse.Error("Enter a valid Email Address")));
        }
Example #14
0
        public async Task <IActionResult> Create(UserCreateViewModel userVM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var oUser = await usrService.GetUserById(userVM.UserID);

                    if (oUser != null)
                    {
                        return(Json(JsonResponse.Error("That User Id already exists.", userVM.UserID, MessageInfoType.Warning)));
                    }

                    var user = mapper.Map <MS_USER>(userVM);

                    var row = await usrService.Add(user);

                    if (row == 0)
                    {
                        return(Json(JsonResponse.Success("No data created", null, MessageInfoType.Info)));
                    }
                    else
                    {
                        return(Json(JsonResponse.Success("The user was successfully created", null, MessageInfoType.Success)));
                    }
                }

                return(Json(JsonResponse.Error("Insufficient data", null, MessageInfoType.Error)));
            } catch (Exception ex) {
                return(Json(JsonResponse.Error(ex.InnerException.Message, null, MessageInfoType.Error)));
            }
        }
Example #15
0
        public async Task <JsonResult> SendPasswordResetEmail(string email)
        {
            if (RegexExtension.IsValidEmail(email))
            {
                UserBO user = await UserManager.FindByEmailAsync(email);

                if (user == null)
                {
                    return(Json(JsonResponse.Success("We've sent you an email to enable you reset your password. Please Check your email for instructions.")));
                }

                try
                {
                    string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                    var callbackUrl = Url.RouteUrl("Organization_PasswordReset",
                                                   new { email = user.Email, code = code }, protocol: Request.Url.Scheme);
                    //string route = "../reset/" + user.UserName + "/" + code; ;

                    string imageUrl = Url.Action("images", "EmailTemplates") + "/head1.png";

                    string emailBody = await CreateEmailBodyAsync("../EmailTemplates/AccountConfirmation.html", user.Email, user.FirstName, callbackUrl, imageUrl);

                    await UserManager.SendEmailAsync(user.Id, "SiriusPM Account Confimation", emailBody);

                    return(Json(JsonResponse.Success("We've sent you an email to enable you reset your password. Please Check your email for instructions.")));
                }
                catch (Exception ex)
                {
                    LogError(ex, string.Empty);
                    return(Json(JsonResponse.Error("Something went wrong, please try again.")));
                }
            }
            return(Json(JsonResponse.Error("Enter a valid Email Address")));
        }
Example #16
0
        public async Task <IActionResult> Edit(string id, UserCreateViewModel userVM)
        {
            try
            {
                if (id != userVM.UserID)
                {
                    return(Json(JsonResponse.Error("User ID do not found", null, MessageInfoType.Error)));
                }

                if (ModelState.IsValid)
                {
                    var user = mapper.Map <MS_USER>(userVM);

                    var row = await usrService.Update(user);

                    if (row == 0)
                    {
                        return(Json(JsonResponse.Success("No data updated", null, MessageInfoType.Info)));
                    }
                    else
                    {
                        return(Json(JsonResponse.Success("The user was successfully updated", null, MessageInfoType.Success)));
                    }
                }

                return(Json(JsonResponse.Error("Update Failed", null, MessageInfoType.Error)));
            }
            catch (Exception ex)
            {
                return(Json(JsonResponse.Error(ex.Message, null, MessageInfoType.Error)));
            }
        }
Example #17
0
 public JsonResult Invite(string email)
 {
     try
     {
         return(Json(JsonResponse.Success("Your successfully accepted this staff.")));
     }
     catch (Exception ex)
     {
         LogError(ex, CurrentUserId);
         return(Json(JsonResponse.Error("Error accepting staff, please try again.")));
     }
 }
Example #18
0
 public JsonResult Distribution()
 {
     try
     {
         var useCase = new UseCase(_logger);
         useCase.Execute(new Core.Modules.Distribution.Request());
         return(JsonResponse.Success());
     }
     catch (System.Exception exception)
     {
         return(JsonResponse.Error(exception.Message));
     }
 }
        public async Task <ActionResult> Password(PasswordSettingViewModel model)
        {
            try
            {
                var result = await UserManager.ChangePasswordAsync(CurrentUserId, model.CurrentPassword, model.NewPassword);

                return(result.Succeeded ? Json(JsonResponse.Success("You have successfully changed your password")) : Json(JsonResponse.Error("Error changing your password, please try again.")));
            }
            catch (Exception ex)
            {
                LogError(ex, CurrentUserId);
                return(Json(JsonResponse.Error("An Error occurred while changing your password, please try again.")));
            }
        }
 public string DeleteProductR([FromBody] int id)
 {
     using (ApplicationContext db = new ApplicationContext())
     {
         var temp = db.Products.Where(a => a.ID == id).ToList();
         if (temp.Count != 0)
         {
             db.Products.Remove(temp[0]);
             db.SaveChanges();
             return(JsonResponse.Success());
         }
         return(JsonResponse.Error("no such product!"));
     }
 }
Example #21
0
        public async Task <JsonResponse> GetProducts()
        {
            try
            {
                var result = await _productService.GetProducts();

                return(JsonResponse.Success(result));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
                return(JsonResponse.Error(ex.Message));
            }
        }
Example #22
0
        public async Task <IActionResult> DeleteConfirmed(string id)
        {
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    return(Json(JsonResponse.Error("User ID Not found", null, MessageInfoType.Error)));
                }

                await usrService.Delete(id);

                return(Json(JsonResponse.Success("Delete Successfully", id, MessageInfoType.Success)));
            } catch (Exception ex)  {
                return(Json(JsonResponse.Success(ex.Message, null, MessageInfoType.Error)));
            }
        }
 public string EditProductsR([FromBody] ProductViewModel product)
 {
     using (ApplicationContext db = new ApplicationContext())
     {
         if (product.ID == 0)
         {
             db.Products.Add(new Product(product));
         }
         else
         {
             var temp = db.Products.Where(a => a.ID == product.ID).ToList();
             if (temp.Count == 0)
             {
                 return(JsonResponse.Error("No such product!"));
             }
             else
             {
                 //List<int> indexes = new List<int>();
                 //for (int i = 0; i < product.Images.Count; i++)
                 //{
                 //    if (product.Images[i] == "")
                 //    {
                 //        indexes.Add(i);
                 //    }
                 //}
                 //indexes.Reverse();
                 //foreach(var index in indexes)
                 //{
                 //    product.Images.RemoveAt(index);
                 //}
                 Product obj = new Product(product);
                 temp[0].Name        = obj.Name;
                 temp[0].Description = obj.Description;
                 temp[0].Cost        = obj.Cost;
                 temp[0].GoodsRemain = obj.GoodsRemain;
                 temp[0].Images      = obj.Images;
                 temp[0].Category    = obj.Category;
             }
         }
         db.SaveChanges();
     }
     return(JsonResponse.Success());
 }
Example #24
0
        public string AddProduct(int id)
        {
            //AuthController.CheckUserLoggedIn(this);
            if (AuthController.IsUserLoggedIn(this) == false)
            {
                return(JsonResponse.Error("user are not logged in!"));
            }
            using (ApplicationContext db = new ApplicationContext())
            {
                var temp = db.Products.Where(a => a.ID == id).ToList();
                if (temp.Count != 1)
                {
                    return(JsonResponse.Error("No such product!"));
                }
                var product = temp[0];

                var email = Request.Cookies["Email"];


                var userPurchase = db.Purchases.Where(a => a.Email == email && a.IsDone == false).ToList();
                if (userPurchase.Count == 0)
                {
                    List <ProductViewModel> products = new List <ProductViewModel>();
                    products.Add(new ProductViewModel(product));
                    Purchase purchase = new Purchase()
                    {
                        Products = JsonSerializer.Serialize(products), IsDone = false, Email = email
                    };
                    db.Purchases.Add(purchase);
                }
                else
                {
                    Purchase purchase         = userPurchase[0];
                    var      purchaseProducts = JsonSerializer.Deserialize <List <ProductViewModel> >(purchase.Products);
                    purchaseProducts.Add(new ProductViewModel(product));
                    purchase.Products = JsonSerializer.Serialize(purchaseProducts);
                }
                db.SaveChanges();
            }
            return(JsonResponse.Success());
        }
        public async Task <ActionResult> AssignSupervisor(string userId)
        {
            try
            {
                bool isSupervisor = await UserManager.IsInRoleAsync(userId, SiriusRoles.SUPERVISOR);

                if (isSupervisor)
                {
                    return(Json(JsonResponse.Error("User is already a supervisor")));
                }

                var result = await UserManager.AddToRoleAsync(userId, SiriusRoles.SUPERVISOR);

                return(result.Succeeded ? Json(JsonResponse.Success("Succesfully added as Supervisor")) : Json(JsonResponse.Error("User cannot be added as supervisor, Please try again.")));
            }
            catch (Exception ex)
            {
                LogError(ex, CurrentUserId);
                return(Json(JsonResponse.Error("Try Again")));
            }
        }
Example #26
0
        public async Task <IActionResult> ResetPasswordAsync(ChangePasswordViewModel passVM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var user = await UserService.GetUserById(passVM.UserId);

                    if (user == null)
                    {
                        return(Json(JsonResponse.Error("Invalid User", null, MessageInfoType.Error)));
                    }

                    if (string.IsNullOrEmpty(user.IResetPin) || user.IResetPin != passVM.PinCode)
                    {
                        return(Json(JsonResponse.Error("Invalid Pin Code", null, MessageInfoType.Error)));
                    }


                    user.IUserPwd  = BCrypt.Net.BCrypt.HashPassword(passVM.NewPassword);
                    user.IResetPin = null;
                    var row = await UserService.Update(user);

                    if (row == 0)
                    {
                        return(Json(JsonResponse.Success("No data updated", null, MessageInfoType.Info)));
                    }
                    else
                    {
                        return(Json(JsonResponse.Success("Your password was successfully changed", null, MessageInfoType.Success)));
                    }
                }

                return(Json(JsonResponse.Error("Insufficient data", null, MessageInfoType.Error)));
            }
            catch (Exception ex)
            {
                return(Json(JsonResponse.Error(ex.InnerException.Message, null, MessageInfoType.Error)));
            }
        }
Example #27
0
 public string RemoveProduct(int id)
 {
     if (AuthController.IsUserLoggedIn(this) == false)
     {
         return(JsonResponse.Error("user are not logged in!"));
     }
     using (ApplicationContext db = new ApplicationContext())
     {
         var email = Request.Cookies["Email"];
         var temp  = db.Purchases.Where(a => a.Email == email && a.IsDone == false).ToList();
         if (temp.Count == 0)
         {
             return(JsonResponse.Error("no such product in the basket!"));
         }
         var purchase         = temp[0];
         var purchaseProducts = JsonSerializer.Deserialize <List <ProductViewModel> >(purchase.Products);
         purchaseProducts.Remove(purchaseProducts.Where(a => a.ID == id).ToList()[0]);
         purchase.Products = JsonSerializer.Serialize(purchaseProducts);
         db.SaveChanges();
     }
     return(JsonResponse.Success());
 }
        public ActionResult EditTask(EditTaskViewModel model)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(model.Title))
                {
                    return(Json(JsonResponse.Error("The title field cannot be empty.")));
                }
                UserTaskBO userTask = zeus.evaluationManager.GetUserTaskById(model.UserTaskId);

                userTask.Title       = model.Title;
                userTask.Description = model.Description;

                zeus.evaluationManager.Update(userTask);
                return(Json(JsonResponse.Success("Your Task has been succesfully Updated.")));
            }
            catch (Exception ex)
            {
                LogError(ex, CurrentUserId);
                return(Json(JsonResponse.Error("An Error occured while editing this task, please try again")));
            }
        }
Example #29
0
 public string DoRegister([FromBody] AuthLoginViewModel model)
 {
     //if (model.Password != model.RePassword)
     //{
     //    return JsonResponse.Error("passwords differ");
     //}
     using (ApplicationContext db = new ApplicationContext())
     {
         var res = db.Users.Where(a => a.Email == model.Email).ToList();
         if (res.Count != 0)
         {
             return(JsonResponse.Error("user already exists"));
         }
         else
         {
             db.Users.Add(new DB.User()
             {
                 Email = model.Email, Password = HashPassword(model.Password), Role = "user"
             });
             db.SaveChanges();
             return(JsonResponse.Success());
         }
     }
 }
Example #30
0
        public static string DeleteEvent(int rowId, UsageEventType eventType)
        {
            try
            {
                lms_Entities db = new ClientDBEntities();
                if (eventType == UsageEventType.SCORE)
                {
                    Courses_Scores cs = db.Courses_Scores.Where(c => c.rowId == rowId).FirstOrDefault();
                    db.Courses_Scores.Remove(cs);
                }
                else
                {
                    Courses_Usage cu = db.Courses_Usage.Where(c => c.rowId == rowId).FirstOrDefault();
                    db.Courses_Usage.Remove(cu);
                }
                db.SaveChanges();

                return(JsonResponse.NoError);
            }
            catch (Exception ex)
            {
                return(JsonResponse.Error(ex));
            }
        }