コード例 #1
0
        //public async Task<TypeBarangResponse> GetTypeByName(TypeBarangRequest request)
        //{
        //    TypeBarangResponse response = new TypeBarangResponse();



        //    return response;
        //}

        public async Task <TypeBarangResponse> AddPost(TypeBarangRequest request)
        {
            TypeBarangResponse response = new TypeBarangResponse();

            try
            {
                TypeBarang req = new TypeBarang();
                req.Name = request.Name;
                TypeBarang model = await dep.GetTypeByName(req);

                if (model != null)
                {
                    response.IsSuccess = false;
                    response.Message   = "Data Duplicate with Existing Data";
                }
                else
                {
                    req.ModelBarangId = request.ModelBarangID;
                    req.Name          = request.Name;
                    req.Description   = request.Description;
                    req.Created       = DateTime.Now;
                    req.CreatedBy     = request.UserName;
                    req.RowStatus     = true;
                    response          = await dep.AddPost(req);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                response.Message   = ex.Message.ToString();
                response.IsSuccess = false;
            }
            return(response);
        }
コード例 #2
0
ファイル: TypeBarangRepository.cs プロジェクト: daytch/ljgb
        public async Task <TypeBarangResponse> AddPost(TypeBarang model)
        {
            TypeBarangResponse response = new TypeBarangResponse();

            try
            {
                if (db != null)
                {
                    await db.TypeBarang.AddAsync(model);

                    await db.SaveChangesAsync();

                    response.Message   = "Data Already Saved!";
                    response.IsSuccess = true;
                }
                else
                {
                    response.Message   = "Opps, Something Error with System Righ Now !";
                    response.IsSuccess = false;
                }
            }
            catch (Exception ex)
            {
                response.Message   = ex.ToString();
                response.IsSuccess = false;
            }

            return(response);
        }
コード例 #3
0
ファイル: TypeBarangRepository.cs プロジェクト: daytch/ljgb
        public async Task <TypeBarangResponse> GetPost(TypeBarangRequest request)
        {
            TypeBarangResponse response = new TypeBarangResponse();

            try
            {
                if (db != null)
                {
                    response.Model = await(from model in db.TypeBarang
                                           where model.Id == request.ID && model.RowStatus == true
                                           select new TypeBarangViewModel
                    {
                        ID            = model.Id,
                        Name          = model.Name,
                        ModelBarangID = model.ModelBarangId,
                        Description   = model.Description,
                        Created       = model.Created,
                        CreatedBy     = model.CreatedBy,
                        Modified      = model.Modified,
                        ModifiedBy    = model.ModifiedBy,
                        RowStatus     = model.RowStatus
                    }).FirstOrDefaultAsync();
                    if (response.Model == null)
                    {
                        response.IsSuccess = true;
                        response.Message   = "Data Not Found";
                    }
                    response.IsSuccess = true;
                    response.Message   = "Load Success";
                }
                else
                {
                    response.Message   = "Opps, Something Error with System Righ Now !";
                    response.IsSuccess = false;
                }
            }
            catch (Exception ex)
            {
                response.Message   = ex.ToString();
                response.IsSuccess = false;

                //return await (from model in db.TypeBarang
                //              where model.Id == ID && model.RowStatus == true
                //              select new TypeBarangViewModel
                //              {
                //                  ID = model.Id,
                //                  Nama = model.Name,
                //                  ModelBarangID = model.ModelBarangId,
                //                  Description = model.Description,
                //                  Created = model.Created,
                //                  CreatedBy = model.CreatedBy,
                //                  Modified = model.Modified,
                //                  ModifiedBy = model.ModifiedBy,
                //                  RowStatus = model.RowStatus
                //              }).FirstOrDefaultAsync();
            }

            return(response);
        }
コード例 #4
0
        public async Task <TypeBarangResponse> DeletePost([FromBody] TypeBarangRequest request)
        {
            TypeBarangResponse resp = new TypeBarangResponse();

            try
            {
                string bearer   = Request.HttpContext.Request.Headers["Authorization"];
                string token    = bearer.Substring("Bearer ".Length).Trim();
                string username = string.Empty;
                if (string.IsNullOrEmpty(token))
                {
                    resp.IsSuccess = false;
                    resp.Message   = "You don't have access.";
                    return(resp);
                }

                username = sec.ValidateToken(token);
                if (username == null)
                {
                    Response.HttpContext.Response.Cookies.Append("access_token", "", new CookieOptions()
                    {
                        Expires = DateTime.Now.AddDays(-1)
                    });
                    resp.IsSuccess = false;
                    resp.Message   = "Your session was expired, please re-login.";
                    return(resp);
                }
                request.UserName = username;

                return(resp = await facade.DeletePost(request));;
            }
            catch (Exception ex)
            {
                resp.IsSuccess = false;
                resp.Message   = ex.Message.ToString();
                return(resp);
            }

            //try
            //{
            //    var result = await facade.DeletePost(request);

            //    return Ok(result);
            //}
            //catch (Exception)
            //{

            //    return BadRequest();
            //}
        }
コード例 #5
0
ファイル: TypeBarangRepository.cs プロジェクト: daytch/ljgb
        public async Task <TypeBarangResponse> DeletePost(TypeBarangRequest request)
        {
            TypeBarangResponse response = new TypeBarangResponse();

            try
            {
                if (db != null)
                {
                    //Find the warna for specific userprofile
                    TypeBarang model = await db.TypeBarang.FirstOrDefaultAsync(x => x.Id == request.ID);

                    if (model != null)
                    {
                        model.Modified   = DateTime.Now;
                        model.ModifiedBy = request.UserName;
                        model.RowStatus  = false;

                        //Commit the transaction
                        await db.SaveChangesAsync();

                        response.Message   = "Data Already Saved";
                        response.IsSuccess = true;
                    }
                    else
                    {
                        response.Message   = "Data Not Found";
                        response.IsSuccess = false;
                    }
                }
                else
                {
                    response.Message   = "Opps, Something Error with System Righ Now !";
                    response.IsSuccess = false;
                }
            }
            catch (Exception ex)
            {
                response.Message   = ex.ToString();
                response.IsSuccess = false;
            }
            return(response);
        }
コード例 #6
0
        public async Task <TypeBarangResponse> GetTypeByKotaIDMerkIDModelID(TypeBarangRequest request)
        {
            TypeBarangResponse response = new TypeBarangResponse();

            try
            {
                response.ListSP__TypeByKotaIDMerkIDModelID = await dep.GetTypeByKotaIDMerkIDModelID(request);

                response.Message   = "Success";
                response.IsSuccess = true;
            }
            catch (Exception ex)
            {
                log.Error(ex);
                response.IsSuccess = false;
                response.Message   = "Failed";
            }

            return(response);
        }
コード例 #7
0
ファイル: TypeBarangRepository.cs プロジェクト: daytch/ljgb
        public async Task <TypeBarangResponse> UpdatePost(TypeBarangRequest request)
        {
            TypeBarangResponse response = new TypeBarangResponse();

            try
            {
                if (db != null)
                {
                    TypeBarang model = await db.TypeBarang.Where(x => x.RowStatus == true && x.Id == request.ID).FirstAsync();

                    model.ModelBarangId = request.ModelBarangID;
                    model.Name          = request.Name;
                    model.Description   = request.Description;
                    model.Modified      = DateTime.Now;
                    model.ModifiedBy    = request.CreatedBy;

                    db.TypeBarang.Update(model);

                    //Commit the transaction
                    await db.SaveChangesAsync();


                    response.Message   = "Data Already Saved";
                    response.IsSuccess = true;
                }
                else
                {
                    response.Message   = "Opps, Something Error with System Righ Now !";
                    response.IsSuccess = false;
                }
            }
            catch (Exception ex)
            {
                response.Message   = ex.ToString();
                response.IsSuccess = false;
            }
            return(response);
        }
コード例 #8
0
ファイル: TypeBarangRepository.cs プロジェクト: daytch/ljgb
        public async Task <TypeBarangResponse> GetAll(string search, string order, string orderDir, int startRec, int pageSize, int draw)
        {
            TypeBarangResponse response = new TypeBarangResponse();

            try
            {
                if (db != null)
                {
                    var query = (from type in db.TypeBarang
                                 join model in db.ModelBarang
                                 on type.ModelBarangId equals model.Id
                                 join merk in db.Merk
                                 on model.MerkId equals merk.Id
                                 where merk.RowStatus == true &&
                                 model.RowStatus == true
                                 select new
                    {
                        type.Id,
                        type.Name,
                        namaModelBarang = model.Name,
                        type.ModelBarangId,
                        NamaMerk = merk.Name,
                        model.MerkId,
                        type.Description,
                        type.Created,
                        type.CreatedBy,
                        type.Modified,
                        type.ModifiedBy,
                        type.RowStatus
                    }
                                 );

                    int totalRecords = query.Count();
                    if (!string.IsNullOrEmpty(search) && !string.IsNullOrWhiteSpace(search))
                    {
                        query = query.Where(p => p.Name.ToString().ToLower().Contains(search.ToLower()) ||
                                            p.namaModelBarang.ToString().ToLower().Contains(search.ToLower()) ||
                                            p.NamaMerk.ToString().ToLower().Contains(search.ToLower()) ||
                                            p.Description.ToLower().Contains(search.ToLower()));
                    }
                    int recFilter = query.Count();
                    response.ListModel = await(from model in query
                                               where model.RowStatus == true
                                               select new TypeBarangViewModel
                    {
                        ID              = model.Id,
                        Name            = model.Name,
                        NamaMerk        = model.NamaMerk,
                        NamaModelBarang = model.namaModelBarang,
                        MerkID          = model.MerkId,
                        ModelBarangID   = model.ModelBarangId,
                        Description     = model.Description,
                        Created         = model.Created,
                        CreatedBy       = model.CreatedBy,
                        Modified        = model.Modified,
                        ModifiedBy      = model.ModifiedBy,
                        RowStatus       = model.RowStatus
                    }).Skip(startRec).Take(pageSize).ToListAsync();
                    response.draw            = Convert.ToInt32(draw);
                    response.recordsTotal    = totalRecords;
                    response.recordsFiltered = recFilter;
                    response.Message         = "Load Success";
                    response.IsSuccess       = true;
                }
                else
                {
                    response.Message   = "Opps, Something Error with System Righ Now !";
                    response.IsSuccess = false;
                }
            }
            catch (Exception ex)
            {
                response.Message   = ex.ToString();
                response.IsSuccess = false;

                //return await (from model in db.TypeBarang
                //              where model.RowStatus == true
                //              select new TypeBarangViewModel
                //              {
                //                  ID = model.Id,
                //                  Nama = model.Name,
                //                  ModelBarangID = model.ModelBarangId,
                //                  Description = model.Description,
                //                  Created = model.Created,
                //                  CreatedBy = model.CreatedBy,
                //                  Modified = model.Modified,
                //                  ModifiedBy = model.ModifiedBy,
                //                  RowStatus = model.RowStatus
                //              }).ToListAsync();
            }

            return(response);
        }