Exemplo n.º 1
0
        public NoteBase AddNoteForAuthenticatedEmployee(NoteAdd newItem)
        {
            // Validate the incoming item, by fetching the employee object
            Employee employee = ds.Employees.Find(newItem.EmployeeId);

            if (employee == null)
            {
                return(null);
            }
            else if (employee.IdentityUserId != User.Identity.Name)
            {// Test whether the user is the same as the security context user
                return(null);
            }
            else
            {// If yes, can add the new note object, and then return it
                Note addedItem = Mapper.Map <Note>(newItem);

                addedItem.Timestamp = DateTime.Now;
                addedItem.Employee  = employee;

                //add to db
                addedItem = ds.Notes.Add(addedItem);
                employee.Notes.Add(addedItem);
                ds.SaveChanges();

                var returnItem = Mapper.Map <NoteBase>(addedItem);
                returnItem.EmployeeId = newItem.EmployeeId;
                ds.SaveChanges();
                return(Mapper.Map <NoteBase>(returnItem));
            }
        }
Exemplo n.º 2
0
        public ActionResult Create(NoteAdd newItem)
        {
            // Standard 'add new' handling
            // Including checking the ModelState
            if (!ModelState.IsValid)
            {
                // If there's a problem with the form data postback, redisplay the form
                var addForm = new NoteAddForm();
                addForm.EmployeeId = newItem.EmployeeId;
                addForm.NoteText   = newItem.NoteText;
                addForm.Title      = newItem.Title;
                // If there's a problem with the form data postback, redisplay the form

                return(View(addForm));
            }
            else
            {
                // Otherwise, whether successful or not, redirect back to the employee's
                // details view
                var addedItem = m.AddNoteForAuthenticatedEmployee(newItem);
                if (addedItem == null)
                {
                    return(HttpNotFound());
                }

                return(RedirectToAction("Details", "Employees", new { id = addedItem.EmployeeId }));
            }
        }
Exemplo n.º 3
0
        public NoteBase AddNoteForAuthenticatedEmployee(NoteAdd newItem)
        {
            // Validate the incoming item, by fetching the employee object
            var fetchedObject = ds.Employees.Find(newItem.EmployeeId);

            if (fetchedObject == null)
            {
                return(null);
            }
            else
            {
                // Test whether the user is the same as the security context user
                if ((User.Identity as ClaimsIdentity).Name == fetchedObject.IdentityUserId)
                {
                    // If yes, can add the new note object, and then return it
                    var addItem = Mapper.Map <Note>(newItem);
                    addItem.Employee = fetchedObject;
                    ds.Notes.Add(addItem);
                    ds.SaveChanges();

                    return(Mapper.Map <NoteBase>(addItem));
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 4
0
        public NoteBase AddNoteForAuthenticatedEmployee(NoteAdd newItem)
        {
            // Validate the incoming item, by fetching the employee object

            // Test whether the user is the same as the security context user
            // If yes, can add the new note object, and then return it

            return null;
        }
Exemplo n.º 5
0
        public ActionResult Create(NoteAdd newItem)
        {
            throw new NotImplementedException();

            // Standard 'add new' handling
            // Including checking the ModelState

            // If there's a problem with the form data postback, redisplay the form
            // Otherwise, whether successful or not, redirect back to the employee's
            // details view
        }