public string SaveNegotiation(int productListId, decimal quantityVal, decimal pricePerItem, decimal totalAmountVal, int status, int orderIdVal) { string message = string.Empty; try { // validation if (OrderLineNegotiationValidator.ValidateOrderLineOrNegotiation(productListId, quantityVal, pricePerItem, totalAmountVal, status, orderIdVal)) { TblNegotiation negotiation = new TblNegotiation() { productId = productListId, quantity = quantityVal, negotiatedPricePerItem = pricePerItem, totalAmount = totalAmountVal, status = CommonBehaviour.GetCommonStatusString(status), negotiationDateTime = DateTime.Now, orderId = orderIdVal }; negotiationRepository.Insert(negotiation); unitOfWork.Save(); message = "success"; } else { message = "Error - Please fill all the mandatory fields"; } } catch (Exception ex) { message = "Error - Server side - Saving negotiation. Please contact IT Support"; } return(message); }
// GET: api/Status public IList <Status> Get() { try { return(CommonBehaviour.GetStatusList()); } catch (Exception) { return(null); } }
public IList <OrderLineViewModel> SavePastOrderlineWithNegotiation(int productListId, decimal quantityVal, decimal pricePerItem, decimal totalAmountVal, int statusVal, int orderIdVal, DateTime orderDate) { try { // validation if (OrderLineNegotiationValidator.ValidateOrderLineOrNegotiation(productListId, quantityVal, pricePerItem, totalAmountVal, statusVal, orderIdVal)) { string status = CommonBehaviour.GetCommonStatusString(statusVal); // call stored procedure via repository var result = orderLineRepository.SQLQuery <OrderLineViewModel>("SP_SavePastOrderLineWithNegotiation @productListId, @quantityVal, @pricePerItem, @totalAmountVal, @status, @orderIdVal, @orderDate", new SqlParameter("productListId", SqlDbType.Int) { Value = productListId }, new SqlParameter("quantityVal", SqlDbType.Int) { Value = quantityVal }, new SqlParameter("pricePerItem", SqlDbType.Decimal) { Value = pricePerItem }, new SqlParameter("totalAmountVal", SqlDbType.Decimal) { Value = totalAmountVal }, new SqlParameter("status", SqlDbType.Text) { Value = status }, new SqlParameter("orderIdVal", SqlDbType.Int) { Value = orderIdVal }, new SqlParameter("orderDate", SqlDbType.DateTime) { Value = orderDate }); // convert the result orderlines (by order ID) IList <OrderLineViewModel> orderLinesOfOrder = result.ToList <OrderLineViewModel>(); orderLinesOfOrder = CommonBehaviour.FixDateTime(orderLinesOfOrder); return(orderLinesOfOrder); } else { return(null); } } catch (Exception ex) { return(null); } }
public async Task <string> CreateUserAsync(string username, string firstname, string lastname, string position, string telephone, int?extension, string employmentDate, string registrationDate) { string message = string.Empty; try { ApplicationUser newUser = new ApplicationUser() { UserName = username, Email = username, EmailConfirmed = true, Title = Enums.Titles.Mr, FirstName = firstname, LastName = lastname, Position = position, DirectDial = telephone, Extension = extension, EmploymentDate = CommonBehaviour.ConvertStrToDateTime(employmentDate), RegistrationDate = CommonBehaviour.ConvertStrToDateTime(registrationDate), LastLogInTime = null, LastLogoutTime = null, IsLoggedIn = false, InvalidLoginAttemptCount = 0, LastInvalidLoginAttemptTime = null, Locked = false }; string temporaryPassword = CommonBehaviour.GenerateTempPassword(); IdentityResult result = await userManager.CreateAsync(newUser, CommonBehaviour.GenerateTempPassword()); // user creation if (result != null && result.Succeeded == true) { SendUserCreationEmail(username, temporaryPassword); message = "Success - user creation successful"; } else { string errors = string.Empty; foreach (string error in result.Errors) { errors += error + " "; } message = string.Format("Error : {0}", errors); } } catch (Exception) { message = "Error - user creation unsuccessful"; } return(message); }
public async Task <string> ResetPasswordAsync(string username) { string message = string.Empty; try { ApplicationUser userToUpdate = userManager.FindByEmail(username); if (userToUpdate != null) { string temporaryPassword = CommonBehaviour.GenerateTempPassword(); string resetPasswordToken = await userManager.GeneratePasswordResetTokenAsync(userToUpdate.Id); IdentityResult result = await userManager.ResetPasswordAsync(userToUpdate.Id, resetPasswordToken, temporaryPassword); if (result != null && result.Succeeded == true) { bool wasEmailed = SendPasswordResetEmail(username, temporaryPassword); if (wasEmailed) { message = "Success - user password reset successful and user notified via email"; } else { message = string.Format("Error - user password reset successful, but unable to send the notification email to {0}. Please contact IT-support", username); } } else { string errors = string.Empty; foreach (string error in result.Errors) { errors += error + " "; } message = string.Format("Error : {0}", errors); } } else { // user not found message = "Error - user password reset unsuccessful"; } } catch (Exception) { message = "Error - user password reset unsuccessful - Contact IT support"; } return(message); }
public IList <OrderLineViewModel> GetAllOrderlinesByOrderId(int orderIdVal) { try { // call stored procedure via repository var result = orderLineRepository.SQLQuery <OrderLineViewModel>("SP_GetOrderLinesByOrderId @orderIdVal", new SqlParameter("orderIdVal", SqlDbType.Int) { Value = orderIdVal }); // convert the result orderlines (by order ID) IList <OrderLineViewModel> orderLinesOfOrder = result.ToList <OrderLineViewModel>(); orderLinesOfOrder = CommonBehaviour.FixDateTime(orderLinesOfOrder); return(orderLinesOfOrder); } catch (Exception ex) { return(null); } }
public async Task <string> UpdateUserAsync(string username, string firstname, string lastname, string position, string telephone, int?extension, string employmentDate, string registrationDate, string locked) { string message = string.Empty; try { ApplicationUser userToUpdate = userManager.FindByEmail(username); userToUpdate.FirstName = firstname; userToUpdate.LastName = lastname; userToUpdate.Position = position; userToUpdate.DirectDial = telephone; userToUpdate.Extension = extension; userToUpdate.EmploymentDate = CommonBehaviour.ConvertStrToDateTime(employmentDate); userToUpdate.RegistrationDate = CommonBehaviour.ConvertStrToDateTime(registrationDate); userToUpdate.Locked = locked == "Yes" ? true:false; IdentityResult result = await userManager.UpdateAsync(userToUpdate); if (result != null && result.Succeeded == true) { message = "Success - user update successful"; } else { string errors = string.Empty; foreach (string error in result.Errors) { errors += error + " "; } message = string.Format("Error : {0}", errors); } } catch (Exception) { message = "Error - user update unsuccessful - Contact IT support"; } return(message); }
private IList <ApplicationUser> SearchUsersHelper(IQueryable <ApplicationUser> users, IQueryable <ApplicationRole> roles, string userRolesCsv, string username, string firstname, string lastname, string position, string employmentDate, string registrationDate, string lastLoginDateTime, string lastInvalidLoginDateTime) { try { IList <ApplicationUser> searchedUsers = new List <ApplicationUser>(); if (GeneralValidator.IsStringNotEmpty(username)) { users = users.Where(u => u.UserName.Contains(username)); } if (GeneralValidator.IsStringNotEmpty(firstname)) { users = users.Where(u => u.FirstName.Contains(firstname)); } if (GeneralValidator.IsStringNotEmpty(lastname)) { users = users.Where(u => u.LastName.Contains(lastname)); } if (GeneralValidator.IsStringNotEmpty(position)) { users = users.Where(u => u.Position.Contains(position)); } if (employmentDate != null) { users = users.Where(u => u.EmploymentDate == CommonBehaviour.ConvertStrToDateTime(employmentDate)); } if (registrationDate != null) { users = users.Where(u => u.RegistrationDate == CommonBehaviour.ConvertStrToDateTime(registrationDate)); } if (lastLoginDateTime != null) { users = users.Where(u => u.LastLogInTime == CommonBehaviour.ConvertStrToDateTime(lastLoginDateTime)); } if (lastInvalidLoginDateTime != null) { users = users.Where(u => u.LastLogInTime == CommonBehaviour.ConvertStrToDateTime(lastInvalidLoginDateTime)); } if (users.Count() > 0) { // filter roles string[] searchRoles = userRolesCsv.Split(','); IList <ApplicationRole> searchAppRoles = new List <ApplicationRole>(); foreach (ApplicationRole role in roles) { foreach (string searchRole in searchRoles) { if (searchRole == role.Name) { searchAppRoles.Add(role); } } } // filter users based on searched roles foreach (ApplicationUser user in users) { //UserRoleLoop: foreach (ApplicationUserRole userRole in user.Roles) { foreach (ApplicationRole searchRole in searchAppRoles) { if (userRole.RoleId == searchRole.Id) { searchedUsers.Add(user); //goto UserRoleLoop; } } } } } return(searchedUsers); } catch (Exception ex) { throw ex; } }
public IEnumerable <OrderViewModel> SearchOrders(int?companyId, string contactFulName, string orderId, string status, string orderType, string creationDateFrom, string creationDateTo) { try { DateTime?fromDate = creationDateFrom != null?CommonBehaviour.ConvertStrToDateTime(creationDateFrom) : (DateTime?)null; DateTime?toDate = creationDateTo != null?CommonBehaviour.ConvertStrToDateTime(creationDateTo) : (DateTime?)null; status = status != "0" ? CommonBehaviour.GetCommonStatusString(int.Parse(status)) : null; orderType = orderType == "0" ? null : orderType; companyId = companyId == -1 ? null : companyId; contactFulName = contactFulName == "-1" ? null : contactFulName; var result = orderRepository.SQLQuery <OrderViewModel>("SP_GetAllOrderViewModels", null); IList <OrderViewModel> orderVms = result.ToList <OrderViewModel>(); // filter by company if (companyId != null) { orderVms = orderVms.Where <OrderViewModel>(o => o.companyId == companyId).ToList <OrderViewModel>(); } // filter by contact full name if (contactFulName != null) { contactFulName = CommonBehaviour.CleanContactFulName(contactFulName); orderVms = orderVms.Where <OrderViewModel>(o => o.contactFulName == contactFulName).ToList <OrderViewModel>(); } // filter by orderId if (orderId != null) { orderVms = orderVms.Where <OrderViewModel>(o => o.id == int.Parse(orderId)).ToList <OrderViewModel>(); } // filter by status if (status != null) { orderVms = orderVms.Where <OrderViewModel>(o => o.status == status).ToList <OrderViewModel>(); } // filter by order type if (orderType != null) { orderVms = orderVms.Where <OrderViewModel>(o => o.type == orderType).ToList <OrderViewModel>(); } // filter by from date if (fromDate != null) { orderVms = orderVms.Where <OrderViewModel>(o => CommonBehaviour.ConvertStrToDateTime(o.orderCreationDate) >= fromDate).ToList <OrderViewModel>(); } // filter by to date if (toDate != null) { orderVms = orderVms.Where <OrderViewModel>(o => CommonBehaviour.ConvertStrToDateTime(o.orderCreationDate) <= toDate).ToList <OrderViewModel>(); } return(orderVms); } catch (Exception ex) { return(null); } }