コード例 #1
0
        public Employee Create(Employee user, string password)
        {
            // validation
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ApplicationException("Password is required");
            }

            if (_context.Employees.Any(x => x.EmailId == user.EmailId))
            {
                throw new ApplicationException("Username \"" + user.EmailId + "\" is already taken");
            }

            //byte[] passwordHash, passwordSalt;
            //CreatePasswordHash(password, out passwordHash, out passwordSalt);

            //user.PasswordHash = passwordHash;

            user.CreatedOn = DateTimeOffset.Now;

            user.Password       = password;
            user.LastModifiedBy = user.FirstName;

            _context.Employees.Add(user);
            _context.SaveChanges();

            return(user);
        }
コード例 #2
0
        public void CreateRequest(Request request)
        {
            var context = new SRMContext();

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            context.Request.Add(request);
            context.SaveChanges();


            var email1     = context.Employees.FirstOrDefault(e => e.Id == request.CreatedEmpId).EmailId;
            var AdminEmail = context.Employees.FirstOrDefault(e => e.DepartmentId == request.DepartmentId && e.RoleId == (context.Roles.FirstOrDefault(r => r.Role1.Equals("Admin")).Id)).EmailId;
            //var fromAddress = new MailAddress("*****@*****.**", "My Name");
            //var toAddress1 = new MailAddress((email1).ToString());
            //var toAddress2 = new MailAddress((AdminEmail).ToString());
            //const string fromPassword = "******";
            string sub     = "Service Request";
            string content = "Request Created!" +
                             "\nRequest Id: " + request.Id +
                             "\nRequest Created by: " + context.Employees.FirstOrDefault(e => e.Id == request.CreatedEmpId).FirstName +
                             "\nDepartment: " + context.Department.FirstOrDefault(d => d.Id == request.DepartmentId).Name +
                             "\nCategory: " + context.Category.FirstOrDefault(c => c.Id == request.CategoryId).Name +
                             "\nSubcategory: " + context.Category.FirstOrDefault(s => s.Id == request.SubCategoryId).Name +
                             "\nTitle :" + request.Title +
                             "\nSummary :" + request.Summary;



            var message = new Message(new string[] { email1, AdminEmail }, sub, content);

            emailSender.SendEmail(message);
        }
コード例 #3
0
ファイル: RequestsController.cs プロジェクト: Ankitalb/SRM
        public ActionResult <Request> CreateRequest(Request createRequest)
        {
            SRMContext context = new SRMContext();

            _repository.CreateRequest(createRequest);
            context.SaveChanges();
            return(createRequest);
        }
コード例 #4
0
        public void UpdateRequest(int serviceRequestId, Request serviceRequest)
        {
            var context = new SRMContext();

            var oldRequest = context.Request.FirstOrDefault(n => n.Id == serviceRequestId);

            if (oldRequest != null)
            {
                //oldRequest.CategoryId = serviceRequest.CategoryId;
                oldRequest.AssignedEmpId = serviceRequest.AssignedEmpId;
                // oldRequest.DepartmentId = serviceRequest.DepartmentId;
                oldRequest.StatusId = serviceRequest.StatusId;
                oldRequest.Summary  = serviceRequest.Summary;
                // oldRequest.Title = serviceRequest.Title;
                // oldRequest.Comments = serviceRequest.Comments;
                oldRequest.LastModifiedOn = serviceRequest.LastModifiedOn;
                oldRequest.LastModifiedBy = serviceRequest.LastModifiedBy;

                context.SaveChanges();
            }


            try
            {
                string CreatedEmpEmail  = context.Employees.FirstOrDefault(e => e.Id == serviceRequest.CreatedEmpId).EmailId;
                string AssignedEmpEmail = context.Employees.FirstOrDefault(e => e.Id == serviceRequest.AssignedEmpId).EmailId;
                string AdminEmail       = context.Employees.FirstOrDefault(e => e.DepartmentId == serviceRequest.DepartmentId && e.RoleId == (context.Roles.FirstOrDefault(r => r.Role1.Equals("Admin")).Id)).EmailId;

                string sub = "Service for  request  " + serviceRequest.Title;
                //string content = JsonConvert.SerializeObject(serviceRequest);

                string content = "Request Id: " + serviceRequest.Id +
                                 "\nRequest Title: " + serviceRequest.Title +
                                 "\nSummary: " + serviceRequest.Summary +
                                 "\nComments: " + context.Comments.OrderByDescending(e => e.Id).FirstOrDefault(e => e.RequestId == serviceRequest.Id).Comment1 +
                                 "\nRequest Created by: " + context.Employees.FirstOrDefault(e => e.Id == serviceRequest.CreatedEmpId).FirstName +
                                 "\nRequest Assigned to: " + context.Employees.FirstOrDefault(e => e.Id == serviceRequest.AssignedEmpId).FirstName;


                if (serviceRequest.StatusId == 2)
                {
                    content = content + "\n request is in process";
                }
                else if (serviceRequest.StatusId == 3)
                {
                    content = content + "\n request has been completed";
                }
                var message = new Message(new string[] { CreatedEmpEmail, AssignedEmpEmail, AdminEmail }, sub, content);
                emailSender.SendEmail(message);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
            }//
        }
コード例 #5
0
ファイル: RequestsController.cs プロジェクト: Ankitalb/SRM
        public ActionResult <Request> DeleteRequest(int Id)
        {
            SRMContext context         = new SRMContext();
            var        requestFromRepo = _repository.GetRequestById(Id);

            if (requestFromRepo == null)
            {
                return(NotFound());
            }
            _repository.DeleteRequest(requestFromRepo);
            context.SaveChanges();
            return(NoContent());
        }
コード例 #6
0
        public IActionResult UpdateRequest(int id, [FromBody] AngularRequestModel obj)
        {
            SRMContext context = new SRMContext();
            //string Comment = obj.Comment;
            Comment c = new Comment();

            c.Comment1       = obj.Comment;
            c.EmployeeId     = obj.AssignedEmpId;
            c.RequestId      = Int32.Parse(obj.RequestId);
            c.CreatedOn      = DateTimeOffset.Now;
            c.LastModifiedOn = DateTimeOffset.Now;
            c.LogTime        = DateTimeOffset.MinValue;
            c.LastModifiedBy = "MAYURESH";

            context.Comments.Add(c);

            context.SaveChanges();
            _service.UpdateRequest(id, obj.SendData());

            return(Ok(obj));
        }
コード例 #7
0
ファイル: SqlDepartmentRepo.cs プロジェクト: Ankitalb/SRM
 public bool SaveChanges()
 {
     return(_context.SaveChanges() >= 0);
 }
コード例 #8
0
 public void Add(Contact contact)
 {
     db.Contacts.Add(contact);
     db.SaveChanges();
 }
コード例 #9
0
 public void Add(Grade grade)
 {
     db.Grades.Add(grade);
     db.SaveChanges();
 }
コード例 #10
0
 public void Add(Course course)
 {
     db.Courses.Add(course);
     db.SaveChanges();
 }
コード例 #11
0
ファイル: DealRepository.cs プロジェクト: TrakBit/srm_backend
 public void Add(Deal deal)
 {
     db.Deals.Add(deal);
     db.SaveChanges();
 }
コード例 #12
0
 public void Add(Module module)
 {
     db.Modules.Add(module);
     db.SaveChanges();
 }