Beispiel #1
0
        public ActionResult CreateUser()
        {
            var formCollection = Request.Form;

            formCollection.TryGetValue(LoginKey, out var login);
            formCollection.TryGetValue("pwd", out var password);

            var user = userDb.Get().FirstOrDefault(u => u.Login == login);

            if (user != null)
            {
                var pwdHash = GetPwdHash(password);
                if (user.PwdHash != pwdHash)
                {
                    return(StatusCode(401));
                }
            }
            else
            {
                userDb.Create(Create(login, password));
            }

            var sid = SessionManager.CreateSession(login);

            Response.Cookies.Append("sid", sid);
            Response.Cookies.Append(LoginKey, login);
            return(StatusCode(201));
        }
Beispiel #2
0
        private void AddIndex(string filePath, string fileName, string user)
        {
            var indexEntity = indexDb.Get(ie => ie.User == user) ?? new IndexEntity(user);

            if (!indexEntity.Hash.ContainsKey(fileName))
            {
                indexEntity.Hash[fileName] = new List <string>();
            }

            var directoryName = Path.GetDirectoryName(filePath);

            if (!indexEntity.Hash[fileName].Contains(directoryName))
            {
                indexEntity.Hash[fileName].Add(directoryName);
            }

            if (indexEntity.Id != null)
            {
                indexDb.Update(indexEntity.Id, indexEntity);
            }
            else
            {
                indexDb.Create(indexEntity);
            }
        }
Beispiel #3
0
        private IActionResult Create([FromBody] M model)
        {
            var _mapDomain = model.MapForDomain();

            if (_mapDomain.Invalid)
            {
                return(BadRequest(new { errors = _mapDomain.Notifications }));
            }

            var isCreated = repository.Create(_mapDomain);

            if (isCreated)
            {
                return(Created(string.Empty, Mapper.Map <M> (_mapDomain)));
            }
            else
            {
                //Validações adicionais usando o repository.
                if (_mapDomain.Valid)
                {
                    return(StatusCode(500));
                }
                else
                {
                    return(BadRequest(new { errors = _mapDomain.Notifications }));
                }
            }
        }
Beispiel #4
0
 public void Create(T entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity", "Objeto do tipo " + typeof(T).Name + " está nulo");
     }
     _serviceBase.Create(entity);
 }
        public IActionResult Post([FromBody] Customer customer)
        {
            if (customer == null)
            {
                return(NotFound());
            }

            return(Execute(() => _baseUserService.Create <CustomerValidator>(customer).Id));
        }
Beispiel #6
0
        public IActionResult Post([FromBody] T item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            return(new ObjectResult(_serv.Create(item)));
        }
        public IActionResult Create([FromBody] Dto dto)
        {
            dto.Id = Guid.NewGuid();

            var entity = _mapper.Map <Entity>(dto);

            _entityService.Create(entity);

            return(Ok(dto));
        }
        protected ActionResult Add(TInsertDto dto)
        {
            if (!ModelState.IsValid)
            {
                throw new EntityValidationException();
            }

            var entity   = MapperHelper.Map <TInsertDto, T>(dto);
            var response = _service.Create(entity);

            return(Ok(response));
        }
Beispiel #9
0
        private void Init()
        {
            var nodes = nodesDb.Get();

            if (!nodes.Any() || nodes.Count > 1 || nodes[0].Name != IndexRoot)
            {
                nodesDb.RemoveAll();
                indexDb.RemoveAll();

                nodesDb.Create(new Node(IndexRoot));
            }
        }
Beispiel #10
0
        private void AddRecordToUserLog(User user)
        {
            var userLog = new CoreUserLog
            {
                DateTime = DateTime.Now,
                Ip       = HttpContext.Current.Request.UserHostAddress,
                LogType  = LogType.Login,
                UserId   = user.Id,
            };

            _userLogService.Create(userLog);
        }
Beispiel #11
0
      public virtual IActionResult Create([FromBody] T newObject)
      {
          if (!ModelState.IsValid)
          {
              return(BadRequest(ModelState));
          }
          try
          {
              var result = _service.Create(newObject);
          }
          catch (EscamboException e)
          {
              return(BadRequest(e.Message));
          }

          return(CreatedAtRoute("default", new { id = newObject.Id }, newObject));
      }
Beispiel #12
0
        public ActionResult Add([FromBody] NoteModel note)
        {
            if (IsSessionNotValid())
            {
                return(StatusCode(403));
            }

            if (note.Note.Length > 500)
            {
                return(ThrowError("Too long"));
            }

            db.Create(
                new Note
            {
                OwnerName = GetLogin(),
                Text      = note.Note,
                IsPublic  = note.IsPublic,
            });
            return(StatusCode(201));
        }
Beispiel #13
0
 public ActionResult <long> AddObj(TEntity obj)
 {
     return(_service.Create(obj));
 }
Beispiel #14
0
 public void Create(TEntityDTO entity)
 {
     _service.Create(_map.Map <TEntity>(entity));
 }
        public async virtual Task <ActionResult> Create(TEntity entity)
        {
            await _service.Create(entity);

            return(RedirectToAction("Index"));
        }
 protected TEntity CreateWithService(TEntity entity)
 {
     entity.CreatedBy = "admin";
     serviceBase.Create(entity);
     return(entity);
 }
 public Task <string> Create(TEntity entity)
 {
     return(_appServiceBase.Create(entity));
 }
 public void Create(TEntity entity)
 {
     _serviceBase.Create(entity);
 }