Example #1
0
        public async Task <Boolean> Create(Model.Processing processing, long userId)
        {
            Boolean result = false;

            try
            {
                if (processing != null)
                {
                    var lastProcessing = await GetLast();

                    if (lastProcessing == null)
                    {
                        processing.ReferenceNumberId = 1001;
                    }
                    else
                    {
                        processing.ReferenceNumberId = lastProcessing.ReferenceNumberId + 1;
                    }
                    processing.ReferenceNumber = "#" + processing.ReferenceNumberId;
                    processing.CreatedOn       = processing.UpdatedOn = DateTime.Now;
                    processing.CreatedById     = userId;
                    if (processing.Agent != null && processing.Agent.Id != 0)
                    {
                        processing.AgentId = processing.Agent.Id;
                    }
                    if (processing.Status != null)
                    {
                        processing.StatusId = processing.Status.Id;
                    }
                    if (processing.Order != null && processing.Order.Id != 0)
                    {
                        processing.OrderId = processing.Order.Id;
                    }
                    if (processing.ProcessingLineItems != null)
                    {
                        foreach (var item in processing.ProcessingLineItems)
                        {
                            item.CreatedOn = item.UpdatedOn = DateTime.Now;
                        }
                    }
                    if (processing.Notes != null)
                    {
                        foreach (var item in processing.Notes)
                        {
                            item.CreatedOn   = item.UpdatedOn = DateTime.Now;
                            item.CreatedById = userId;
                        }
                    }
                    _context.Update(processing);
                    result = await _context.SaveChangesAsync() > 0;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(result);
        }
Example #2
0
 /// <summary>
 /// Insert a Processing.
 /// </summary>
 public void Insert(Model.Processing processing)
 {
     //
     // todo:add other logic here
     //
     Validate(processing);
     processing.InsertTime = DateTime.Now;
     // processing.CustomerId = processing.Customer.CustomerId;
     //processing.ProcessCategoryId = processing.ProcessCategory.ProcessCategoryId;
     processing.ProcessId = Guid.NewGuid().ToString();
     accessor.Insert(processing);
 }
Example #3
0
 /// <summary>
 /// Update a Processing.
 /// </summary>
 public void Update(Model.Processing processing)
 {
     //
     // todo: add other logic here.
     //
     // if(this.ExistsConcent(processing.Content,processing.ProcessId))
     //  throw new  Helper.InvalidValueException(Model.Processing.PROPERTY_CONTENT);
     Validate(processing);
     processing.UpdateTime = DateTime.Now;
     // processing.CustomerId = processing.Customer.CustomerId;
     //processing.ProcessCategoryId = processing.ProcessCategory.ProcessCategoryId;
     accessor.Update(processing);
 }
Example #4
0
 public async Task <Model.Processing> Get(long Id)
 {
     Model.Processing result = null;
     try
     {
         result = await _context.Processings.FindAsync(Convert.ToInt64(Id));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     return(result);
 }
Example #5
0
 private void Validate(Model.Processing processing)
 {
     //if (processing.Customer == null)
     //{
     //    throw new Helper.RequireValueException(Model.Processing.PROPERTY_CUSTOMERID);
     //}
     if (string.IsNullOrEmpty(processing.ProcessCategoryId))
     {
         throw new Helper.RequireValueException(Model.Processing.PROPERTY_PROCESSCATEGORYID);
     }
     if (string.IsNullOrEmpty(processing.Content))
     {
         throw new Helper.RequireValueException(Model.Processing.PROPERTY_CONTENT);
     }
 }
        public async Task <IActionResult> Update([FromBody] Model.Processing processing)
        {
            try
            {
                var isUpdated = await _coreProcessing.Update(processing);

                if (isUpdated)
                {
                    return(Ok(processing));
                }
                return(BadRequest());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Example #7
0
        public async Task <Model.Processing> GetLast()
        {
            List <Model.Processing> Entities = null;

            Model.Processing result = null;
            try
            {
                Entities = await _context.Processings.ToListAsync();

                result = Entities.OrderByDescending(x => x.CreatedOn).FirstOrDefault();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(result);
        }
Example #8
0
        public async Task <Boolean> Update(Model.Processing processing)
        {
            Boolean result = false;

            try
            {
                if (processing != null)
                {
                    processing.UpdatedOn = DateTime.Now;
                    if (processing.Agent != null && processing.Agent.Id != 0)
                    {
                        processing.AgentId = processing.Agent.Id;
                    }
                    if (processing.Status != null)
                    {
                        processing.StatusId = processing.Status.Id;
                    }
                    if (processing.Order != null && processing.Order.Id != 0)
                    {
                        processing.OrderId = processing.Order.Id;
                    }
                    foreach (var item in processing.ProcessingLineItems)
                    {
                        item.UpdatedOn = DateTime.Now;
                    }
                    foreach (var item in processing.Notes)
                    {
                        item.UpdatedOn = DateTime.Now;
                    }
                    _context.Update(processing);
                    result = await _context.SaveChangesAsync() > 0;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(result);
        }
        public async Task <IActionResult> Create([FromBody] Model.Processing processing)
        {
            try
            {
                string storeId = User.Claims.First(c => c.Type == "userId").Value; // Get stored user id when user sign in or sign up
                if (!string.IsNullOrEmpty(storeId))
                {
                    var userId    = Convert.ToInt64(storeId);
                    var isCreated = await _coreProcessing.Create(processing, userId);

                    if (isCreated)
                    {
                        return(Created("", processing));// return created status 200 when request is successfull;
                    }
                }

                return(BadRequest());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Example #10
0
 public Model.Processing GetNext(Model.Processing e)
 {
     return(accessor.GetNext(e));
 }
Example #11
0
 public Model.Processing GetPrev(Model.Processing e)
 {
     return(accessor.GetPrev(e));
 }
Example #12
0
 public bool HasRowsAfter(Model.Processing e)
 {
     return(accessor.HasRowsAfter(e));
 }
Example #13
0
 public bool HasRowsBefore(Model.Processing e)
 {
     return(accessor.HasRowsBefore(e));
 }