Exemple #1
0
        public HttpResponseMessage Get([FromUri] DealerTransaction transaction)
        {
            var restrequest = new RestRequest("dealertransaction/getTransactions", ContentMediaType.Json);

            restrequest.AddQueryStringParameters(new QueryStringParameter {
                Name = "fromDate", Value = transaction.FromDate.ToString("yyyy-MM-dd")
            });
            restrequest.AddQueryStringParameters(new QueryStringParameter {
                Name = "toDate", Value = transaction.ToDate.ToString("yyyy-MM-dd")
            });
            restrequest.AddQueryStringParameters(new QueryStringParameter {
                Name = "transactionStatus", Value = transaction.TransactionStatus
            });
            restrequest.AddQueryStringParameters(new QueryStringParameter {
                Name = "dealerId", Value = transaction.DealerId.ToString()
            });
            var trans = this.restClient.GetData <ApiResponse <List <DealerTransaction> > >(restrequest);

            if (trans.Item1.Status)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, trans.Item1.DataModel));
            }

            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "We are experience some technical error. Please try again later."));
        }
Exemple #2
0
        public HttpResponseMessage Put([FromBody] DealerTransaction transaction)
        {
            var restrequest = new RestRequest("dealertransaction/update", ContentMediaType.Json);

            transaction.SeperatedStockItemIds        = string.Join(",", transaction.StockItems.Select(p => p.StockItemId.ToString()).ToArray());
            transaction.SeperatedStockItemQuantities = string.Join(",", transaction.StockItems.Select(p => p.Quantity.ToString()).ToArray());
            var data = this.restClient.PutData <ApiResponse <DealerTransaction>, DealerTransaction>(restrequest, transaction);

            if (data.Item1.Status)
            {
                return(Request.CreateResponse(HttpStatusCode.Created, new { Message = "transaction updated successfully" }));
            }

            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "We are experience some technical error. Please try again later."));
        }
Exemple #3
0
        public HttpResponseMessage Post([FromBody] DealerTransaction transaction)
        {
            var    restrequest = new RestRequest("dealertransaction/create", ContentMediaType.Json);
            string fileName    = GetFileName(transaction);

            transaction.InvoiceUrl                   = "/Photos/Invoice/" + fileName;
            transaction.SeperatedStockItemIds        = string.Join(",", transaction.StockItems.Select(p => p.StockItemId.ToString()).ToArray());
            transaction.SeperatedStockItemQuantities = string.Join(",", transaction.StockItems.Select(p => p.Quantity.ToString()).ToArray());
            transaction.SeperatedStockItemPrices     = string.Join(",",
                                                                   transaction.StockItems.Select(p => p.UnitPrice.ToString()).ToArray());
            var data = this.restClient.PostData <ApiResponse <DealerTransaction>, DealerTransaction>(restrequest, transaction);

            if (data.Item1.Status)
            {
                return(Request.CreateResponse(HttpStatusCode.Created, new { Message = "Stock buying completed successfully", FileName = fileName }));
            }

            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "We are experience some technical error. Please try again later."));
        }
Exemple #4
0
 private string GetFileName(DealerTransaction transaction)
 {
     return(transaction.DealerId + DateTime.Now.ToString("ddMMyyyyhhmmss") + ".jpg");
 }
        public string InsertTransaction2(string BalanceType, string Type, string Id, Input <ProcessIN2> obj, ProcessDTO rep, string FailureReason, string Status, List <Double> Balances)
        {
            try
            {
                ParameterExpression expression12;
                new Random();
                DealerTransaction entity = new DealerTransaction();
                if (obj.input.usertype == GlobalDealerEnums.Role.AccountUser.ToString())
                {
                    var type = (from a in db.Tbl_Accounts join b in db.Agents on a.AgentId equals(int?) b.Id join c in db.Dealers on b.DealerId equals c.Id
                                where a.AccountId == obj.input.AccountId
                                select new
                                { AccountName = a.AccountName, AgentId = a.AgentId, AgentName = b.AgentName, DealerId = b.DealerId, DealerName = c.DealerName }).FirstOrDefault();
                    if (type != null)
                    {
                        entity.AgentId     = new int?(Convert.ToInt32(type.AgentId));
                        entity.DealerId    = new int?(type.DealerId);
                        entity.AgentName   = type.AgentName;
                        entity.DealerName  = type.DealerName;
                        entity.AccountName = type.AccountName;
                    }
                    entity.AccountId     = new int?(obj.input.AccountId);
                    entity.AccountUser   = (from a in this.db.users where (a.EntityId == obj.input.AccountUserId) && (a.RoleID == 6)  select a.name).FirstOrDefault();
                    entity.AccountUserId = new int?(obj.input.AccountUserId);
                }
                else if (obj.input.usertype == GlobalDealerEnums.Role.Agent.ToString())
                {
                    var type2 = (from b in db.Agents
                                 join c in db.Dealers on b.DealerId equals c.Id
                                 where b.Id == obj.input.AccountId
                                 select new
                                 { AccountName = "", AgentId = b.Id, AgentName = b.AgentName, DealerId = b.DealerId, DealerName = c.DealerName }).FirstOrDefault();
                    if (type2 != null)
                    {
                        entity.AgentId     = new int?(Convert.ToInt32(type2.AgentId));
                        entity.DealerId    = new int?(type2.DealerId);
                        entity.AgentName   = type2.AgentName;
                        entity.DealerName  = type2.DealerName;
                        entity.AccountName = type2.AccountName;
                    }
                    //entity.AccountId = new int?(obj.input.AccountId);
                    //entity.AccountUser = (from a in this.db.users where (a.EntityId == obj.input.AccountUserId) && (a.RoleID == 6) select a.name).FirstOrDefault();
                    //entity.AccountUserId = new int?(obj.input.AccountUserId);
                }
                else
                {
                    var type2 = (from c in db.Dealers
                                 where c.Id == obj.input.AccountId
                                 select new
                                 { AccountName = "", AgentId = 0, AgentName = "", DealerId = c.Id, DealerName = c.DealerName }).FirstOrDefault();
                    if (type2 != null)
                    {
                        entity.AgentId     = new int?(Convert.ToInt32(type2.AgentId));
                        entity.DealerId    = new int?(type2.DealerId);
                        entity.AgentName   = type2.AgentName;
                        entity.DealerName  = type2.DealerName;
                        entity.AccountName = type2.AccountName;
                    }
                    //entity.AccountId = new int?(obj.input.AccountId);
                    //entity.AccountUser = (from a in this.db.users where (a.EntityId == obj.input.AccountUserId) && (a.RoleID == 6) select a.name).FirstOrDefault();
                    //entity.AccountUserId = new int?(obj.input.AccountUserId);
                }

                entity.ServiceId         = new int?(obj.input.ServiceId);
                entity.ServiceCode       = obj.input.serviceName;
                entity.ServiceRefference = obj.input.serviceName;
                entity.Amount            = new double?(Convert.ToDouble(obj.input.paymentamount));
                entity.CountryCode       = obj.input.countryCode;
                entity.DeviceId          = new int?(obj.input.DeviceID);
                entity.DeviceIMEI        = (from a in this.db.Devices
                                            where a.Id == obj.input.DeviceID
                                            select a.IMEI).FirstOrDefault <string>();
                entity.MobileNumber   = obj.input.msisdn;
                entity.PaymentChannel = obj.input.paymentChannelCode;
                entity.TrackID        = obj.input.transactionId;

                if (rep != null)
                {
                    entity.OperatorReference = rep.operatorRef;
                    entity.PaymentReference  = "";
                    entity.Pin    = rep.pin;
                    entity.Serial = rep.serial;
                    if (rep.status != null)
                    {
                        entity.Status  = rep.status;
                        entity.Details = rep.statusDescription;
                    }
                    else
                    {
                        entity.Status  = Status;
                        entity.Details = FailureReason;
                    }
                }
                else
                {
                    entity.Status  = Status;
                    entity.Details = FailureReason;
                }
                entity.TransactionDate = new DateTime?(DateTime.Now);
                entity.UpdatedOn       = new DateTime?(DateTime.Now);
                entity.info1           = BalanceType;
                entity.info2           = Type;
                entity.info3           = Id;
                entity.DeductedAmount  = Balances[0];
                entity.Commission      = Balances[1];
                this.db.DealerTransactions.Add(entity);
                this.db.SaveChanges();
                return(entity.Id.ToString());
            }
            catch (Exception exception)
            {
                return("ERROR" + exception.Message);
            }
        }
        public String InsertTransaction(String BalanceType, String Type, String Id, Models.Input <Models.Inputs.ProcessIN> obj, Models.Outputs.ProcessDTO rep, String FailureReason, String Status)
        {
            try
            {
                String Trackid = "";

                Random            rnd = new Random();
                DealerTransaction tr  = new DealerTransaction();

                var ACCDeatils = (from a in db.Tbl_Accounts
                                  join b in db.Agents on a.AgentId equals b.Id
                                  join c in db.Dealers on b.DealerId equals c.Id
                                  where a.AccountId == obj.input.AccountId
                                  select new { a.AccountName, a.AgentId, b.AgentName, b.DealerId, c.DealerName }).FirstOrDefault();
                if (ACCDeatils != null)
                {
                    tr.AgentId     = Convert.ToInt32(ACCDeatils.AgentId);
                    tr.DealerId    = ACCDeatils.DealerId;
                    tr.AgentName   = ACCDeatils.AgentName;
                    tr.DealerName  = ACCDeatils.DealerName;
                    tr.AccountName = ACCDeatils.AccountName;
                }
                tr.AccountId         = obj.input.AccountId;
                tr.AccountUser       = obj.param.username;
                tr.AccountUserId     = obj.input.AccountUserId;
                tr.ServiceId         = obj.input.ServiceId;
                tr.ServiceCode       = obj.input.seriviceCode;
                tr.ServiceRefference = obj.input.serviceName;
                tr.Amount            = obj.input.PaymentAmount;
                tr.CountryCode       = obj.input.countryCode;
                tr.DeviceId          = obj.input.DeviceID;
                tr.DeviceIMEI        = (from a in db.Devices where a.Id == obj.input.DeviceID select a.IMEI).FirstOrDefault();
                tr.MobileNumber      = obj.input.msisdn;
                tr.PaymentChannel    = obj.input.PaymentChannel;
                tr.TrackID           = obj.input.transactionId;

                if (rep != null)
                {
                    tr.OperatorReference = rep.operatorRef;
                    tr.PaymentReference  = "";
                    tr.Pin    = rep.pin;
                    tr.Serial = rep.serial;
                    if (rep.status != null)
                    {
                        tr.Status  = rep.status;
                        tr.Details = rep.statusDescription;
                    }
                    else
                    {
                        tr.Status  = Status;
                        tr.Details = FailureReason;
                    }
                }
                else
                {
                    tr.Status  = Status;
                    tr.Details = FailureReason;
                }


                tr.TransactionDate = DateTime.Now;
                tr.UpdatedOn       = DateTime.Now;
                tr.info1           = BalanceType;
                tr.info2           = Type;
                tr.info3           = Id;

                db.DealerTransactions.Add(tr);
                db.SaveChanges();

                Trackid = tr.Id.ToString();



                return(Trackid);
            }
            catch (Exception ex)
            {
                return("ERROR" + ex.Message);
            }
        }